useBoolean
Custom hook that handles boolean state with useful utility functions.
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/false, and resetting to the initial value.
This hook is particularly useful for managing UI states such as modals, accordions, toggles, and other interactive elements that need boolean control with clean, semantic function names.
Loading...
Installation
pnpm dlx shadcn@latest add https://shaddy-docs.vercel.app/r/use-boolean
API
▸ useBoolean(initialValue): [boolean, Controls]
| Name | Type | Required | Description |
|---|---|---|---|
| initialValue | boolean | Yes | The initial value for the boolean state. |
Returns [value, controls]:
value(boolean): The current boolean state value.controls(object):setValue(value: boolean): Set the state directly.toggle(): Toggle the state.setTrue(): Set state totrue.setFalse(): Set state tofalse.reset(): Reset to initial value.getValue(): Get the current value.