Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rijvi-mahmud/shaddy/llms.txt
Use this file to discover all available pages before exploring further.
useBoolean is a simple but powerful custom React hook that provides convenient utilities for managing boolean state values. It encapsulates common boolean operations like toggling, setting to true or false, and resetting to the initial value — eliminating the repetitive setState(!value) boilerplate that appears in nearly every React project. It is especially useful for controlling modals, drawers, accordions, toggles, and any other UI element that maps naturally to an on/off state.
Installation
Signature
Parameters
The initial value for the boolean state. This value is also used by
reset() to restore the state to its original setting.Return Value
useBoolean returns a two-element tuple.
The current boolean state value.
An object containing control functions for the boolean state.
Usage
Notes
reset()restores the state to theinitialValuethat was passed on the first render. IfinitialValuechanges between renders,reset()still uses the original value captured at mount time.getValue()is memoised withuseCallbackand always returns the most recent state. It is useful when you need to read the current value inside an event handler or async callback without causing stale closure issues.- All control functions have stable references across renders, making them safe to pass as props or include in dependency arrays.