shadcn-ahooks

useBoolean

A hook that elegantly manages boolean state.

Overview

A hook that elegantly manages boolean state.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useBoolean.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useBoolean.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useBoolean.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useBoolean.json

A 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

PropertyDescriptionType
toggleToggle state() => void
setSet state(value: boolean) => void
setTrueSet state to true() => void
setFalseSet state to false() => void

On this page