useBoolean
A hook that elegantly manages boolean state.
Overview
A hook that elegantly manages boolean state.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useBoolean.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useBoolean.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useBoolean.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useBoolean.jsonA hook that elegantly manages boolean state.
Examples
Default usage
API
const [state, { toggle, set, setTrue, setFalse }] = useBoolean(
defaultValue?: boolean,
);Params
| Property | Description | Type | Default |
| | | - |
| defaultValue | The default value of the state. Optional. | boolean | false |
Result
| Property | Description | Type |
|---|---|---|
| toggle | Toggle state | () => void |
| set | Set state | (value: boolean) => void |
| setTrue | Set state to true | () => void |
| setFalse | Set state to false | () => void |