diff --git a/src/useToggleState.ts b/src/useToggleState.ts new file mode 100644 index 0000000..e69ba86 --- /dev/null +++ b/src/useToggleState.ts @@ -0,0 +1,31 @@ +import { useReducer, Reducer } from 'react' + +/** + * Create a state setter pair for a boolean value that can be "switched". + * Unlike `useState(false)`, `useToggleState` will automatically flip the state + * value when its setter is called with no argument. + * + * @param initialState The initial boolean value + * @returns A tuple of the current state and a setter + * + * ```jsx + * const [show, toggleShow] = useToggleState(false) + * + * return ( + * <> + *