use-toggle
Switches between given values
Source
Docs
PackageIcon
Usage
The use-toggle hook implements a common state pattern – it switches state between given values:
API
The hook accepts an array as a single argument; the first option will be used as the default value.
The hook returns an array with the state value and toggle function:
If you do not provide an array with options, then use-toggle will use boolean values with false as the default:
Set type
By default, TypeScript will guess your type, but in most cases it's better to use const assertion to prevent type widening:
Definition
Exported types
The UseToggleReturnValue type is exported from @mantine/hooks;