import { Reducer , useReducer } from 'react' ; const toggleReducer = ( state , nextValue ? ) => typeof nextValue === 'boolean' ? nextValue : ! state ; const useToggle = ( initialValue ) : [ boolean , ( nextValue ? : any ) => void ] => { return useReducer < Reducer < boolean , any > > ( toggleReducer , initialValue ) ; } ; export default useToggle ;