Skip to content
On this page

useToggle

A hook that toggle states.

Code demonstration

Basic usage

Advanced usage

API

const [state, { toggle, set, setLeft, setRight }] = useToggle(defaultValue?: boolean);
const [state, { toggle, set, setLeft, setRight }] = useToggle<T>(defaultValue: T);
const [state, { toggle, set, setLeft, setRight }] = useToggle<T, U>(defaultValue: T, reverseValue: U);
const [state, { toggle, set, setLeft, setRight }] = useToggle(defaultValue?: boolean);
const [state, { toggle, set, setLeft, setRight }] = useToggle<T>(defaultValue: T);
const [state, { toggle, set, setLeft, setRight }] = useToggle<T, U>(defaultValue: T, reverseValue: U);

Params

PropertyDescriptionTypeDefault
defaultValueThe default value. OptionalTfalse
reverseValueThe reverse value. OptionalU-

Result

PropertyDescriptionType
stateCurrent stateReadonly<Ref<any>>
actionsA set of methods to update state valueActions

Actions

PropertyDescriptionType
toggleToggle state() => void
setSet state(state: T | U) => void
setLeftSet state to defaultValue() => void
setRightSet state to reverseValue if reverseValue is available. Otherwise set it to the reverse of defaultValue() => void

Source

SourceDocsDemo