useBoolean

A hook that elegantly manages boolean state.

Examples

Default usage

Effects:true

Basic usage

Toggle boolean, default value can be set optionally.

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 valueAccessor<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