import React from 'react' ; import { History } from '../interfaces/history' ; export const useHistory = ( defaultValue ) => { const [ history , setHistory ] = React . useState < Array < History > > ( defaultValue ) ; const [ command , setCommand ] = React . useState < string > ( '' ) ; return { history , command , setHistory : ( value ) => setHistory ( [ ... history , { id : history . length , date : new Date ( ) , command , output : value , } , ] ) , setCommand , clearHistory : ( ) => setHistory ( [ ] ) , } ; } ;