useToggle

A hook that switch value between two states.

The API is different from ahooks.

Examples

Basic usage

API

const [state, { toggle, setLeft, setRight }] = useToggle(
  defaultValue?: boolean,
);

const [state, { toggle, setLeft, setRight }] = useToggle(
  defaultValue: any = false,
  reverseValue?: any,
);

Params

PropertyDescriptionTypeDefault
defaultValueOptional,set a default valuenumber | string | boolean | undefinedfalse
reverseValueOptional,set a reverse valuenumber | string | boolean | undefined-

Result

PropertyDescriptionType
statestate value-
actionsOperation setActions

Actions

PropertyDescriptionType
toggleTrigger state change(state?: any) => void
setLeftSet defaultValue() => void
setRightSet reverseValue() => void

最近更新: