React hook for toggle state.
npm install react-use-toggle
React hook for toggle state.
Using npm:
``sh`
$ npm install --save react-use-toggle
Using yarn:
`sh`
$ yarn add react-use-toggle
Since this module uses React's new Hooks feature,
to try this out you'll need to install at least version 16.8.0react
of and react-dom:
`sh`
$ yarn add react@^16.8.0 react-dom@^16.8.0
`js
import React from 'react';
import useToggle from 'react-use-toggle';
function Example() {
const [checked, toggle] = useToggle(false);
return (
);
}
`
`js``
useToggle(initialState?: boolean): [boolean, () => void]
Receives an optional initial state and returns a tuple with the current state
and a function to toggle the state.
Please feel free to submit any issues or pull requests.
MIT