useToggle
A hook that toggles a boolean value.
Installation
Install the custom hook from your command line.
npm i @raddix/use-toggle
Usage
Basic example
In this example, we are going to expand or hide the text of a paragraph. by clicking a button (read more/read less).
API
Result
The useToggle
hook returns an array with the following elements:
Index | Description | Type |
---|---|---|
0 | The current value of the state. | boolean |
1 | A function to change the state. | function |
2 | A function to toggle the state. | function |
Parameters
Name | Description | Required | Default Value | Type |
---|---|---|---|---|
initialValue | The initial value of the boolean state. | No | false | boolean |