@dprovodnikov/use-toggle
v1.0.4
Published
A react hook containing basic toggle behaviour
Downloads
18
Maintainers
Readme
useToggle
Intent
This react hook extracts toggle behaviour so you can only focus on the appearance of your components.
Usage example
import React from 'react';
import useToggle from '@dprovodnikov/use-toggle';
const Toggle = function () {
const handleChange = value => console.log('Toggle has changed its value to', value);
const [isOn, toggle] = useToggle(false, handleChange);
return (
<button onClick={toggle}>
{isOn ? 'Turn off' : 'Turn on'}
</button>
);
};
export default Toggle;
The hooks takes a default value as the first argument, and a change listener function as the second.
Install
$ npm i @dprovodnikov/use-toggle
Requirements
- React^16.8
License
MIT