Skip to content
On this page

useBoolean

A hook that elegantly manages boolean state.

Code demonstration

API

const [state, { toggle, set, setTrue, setFalse }] = useBoolean(
defaultValue? : boolean,
);
const [state, { toggle, set, setTrue, setFalse }] = useBoolean(
defaultValue? : boolean,
);

Params

PropertyDescriptionTypeDefault
defaultValueThe default value of the state. Optional.booleanfalse

Result

PropertyDescriptionType
stateCurrent valueReadonly<Ref<boolean>>
actionsA set of methods to update state valueActions

Actions

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