diff --git a/src/useToggle.ts b/src/useToggle.ts index 61f00ff9..db73d4de 100644 --- a/src/useToggle.ts +++ b/src/useToggle.ts @@ -1,10 +1,9 @@ import { useReducer, Reducer } from 'react'; +const toggleReducer = (state: boolean, nextValue?: any) => (typeof nextValue === 'boolean' ? nextValue : !state); + const useToggle = (initialValue: boolean): [boolean, (nextValue?: any) => void] => { - return useReducer>( - (state: boolean, nextValue?: any) => (typeof nextValue === 'boolean' ? nextValue : !state), - initialValue - ); + return useReducer>(toggleReducer, initialValue); }; export default useToggle;