use-toggle
Switch between two states
Import
Source
Docs
Package
Usage
use-toggle implements a common state pattern – it switches state between two given values:
API
Hook accepts two arguments:
initialValue
– initial stateoptions
– an array with 2 elements, must include initial value
Hook returns an array with state value and toggle function:
TypeScript
Set type
By default, TypeScript will guess your type, but in most cases it's better to set type manually: