useToggle
Toggles state between given values.
Installation
Install the custom hook from your command line.
npm i @raddix/use-toggle
Usage
To toggle the state between given values add an array to the useToggle
hook.
The first element of the array will be used by default as the initial value, you can override this by adding the desired initial value as the second parameter.
API
Parameters
Name | Description | Required | Default Value | Type |
---|---|---|---|---|
values | An array of values | Yes | - | Array<T> |
initValue | initial value | No | values[0] | T |
Result
The useToggle
hook returns an array with the following elements:
Index | Description | Type |
---|---|---|
[0] | The current value of the state. | T |
[1] | A function to toggle the state. | function |
[2] | A function to change the state. | function |