useBooleanState
useBooleanState
is a React hook that simplifies managing a boolean state. It provides functions to set the state to true
, set it to false
, and toggle its value.
Interface
ts
function useBooleanState(
defaultValue: boolean = false
): readonly [
state: boolean,
setTrue: () => void,
setFalse: () => void,
toggle: () => void,
];
Parameters
- defaultValueboolean
The initial value of the state. Defaults to
false
.
Return Value
- readonly [state: boolean, setTrue: () => void, setFalse: () => void, toggle: () => void]
tuple containing:
- stateboolean
The current state value.
- setTrue() => void
A function to set the state to
true
. - setFalse() => void
A function to set the state to
false
. - toggle() => void
A function to toggle the state.
- stateboolean
Example
tsx
const [open, openBottomSheet, closeBottomSheet, toggleBottomSheet] =
useBooleanState(false);