Skip to Content
ohooks

useBoolean

Manages a boolean state with helper functions to set, reset, and toggle the value.

Loading preview...

The useBoolean hook manages a boolean state and provides memoized helper callbacks (setTrue, setFalse, toggle, and setValue) for common state transitions.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useBoolean.json

Usage

Examples

Controlling a Dialog

Use setTrue and setFalse directly as event handlers without creating inline arrow functions.

Toggling State

Use toggle to flip the current boolean value, or setValue when you need to pass an explicit boolean.

API Reference

UseBooleanReturn

State and helper functions returned by the hook.

Property
Specification
value
union
Current boolean state
setValue
Dispatch<SetStateAction<union>>
Standard React state setter
setTrue
function
Sets the state to true
setFalse
function
Sets the state to false
toggle
function
Flips the current boolean state