mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
Also reduce max line width to 100. And remove `lint:types` step for commit sequence, it bothers when committing incomplete (wip) changes.
11 lines
349 B
TypeScript
11 lines
349 B
TypeScript
import { Reducer, useReducer } from 'react';
|
|
|
|
const toggleReducer = (state: boolean, nextValue?: any) =>
|
|
typeof nextValue === 'boolean' ? nextValue : !state;
|
|
|
|
const useToggle = (initialValue: boolean): [boolean, (nextValue?: any) => void] => {
|
|
return useReducer<Reducer<boolean, any>>(toggleReducer, initialValue);
|
|
};
|
|
|
|
export default useToggle;
|