import { useCallback , useState } from "react" ; export default function useToggle ( initialState = false ) { const [ state , setState ] = useState ( initialState ) ; const toggle = useCallback ( ( nextState ? ) => { if ( nextState !== undefined ) { setState ( nextState ) ; } else { setState ( ( state ) => ! state ) ; } } , [ ] ) ; return [ state , toggle ] ; }