A React Hooks package for toggle
npm install @rooks/use-toggle```
npm install rooks
or
``
yarn add rooks
Rooks is completely treeshakeable and if you use only 1 of the 50+ hooks in the package, only that hook will be bundled with your code. Your bundle will only contain the hooks that you need. Cheers!
!Build Status   
``
npm install --save @rooks/use-toggle
`javascript`
import useToggle from "@rooks/use-toggle"
`jsx
const customToggleFunction = v => (v === "start" ? "stop" : "start");
function Demo() {
const [value1, toggleValue1] = useToggle();
const [value2, toggleValue2] = useToggle(true);
const [value3, toggleValue3] = useToggle(
"start",
customToggleFunction
);
return (
<>
Base
Initial true
Custom values
>
);
}
render(
``
| Arguments | Type | Description | Default value |
| -------------- | -------- | ----------------------------------------------- | ------------- |
| initialValue | boolean | Initial value of the state | false |
| toggleFunction | function | Function which determines how to toggle a value | v => !v |
| Returned Array items | Type | Description |
| -------------------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
| value | Any | Current value |
| toggleValue | function | Toggle function which changes the value to the other value in the list of 2 acceptable values. (Mostly true or false) |