use-ref-toggle
v0.1.1
Published
React hook for ref toggle state
Downloads
4
Readme
use-ref-toggle
React hook for ref toggle state
Installation
yarn add use-ref-toggle
Usage
import useRefToggle from 'use-ref-toggle';
const App = () => {
const [ref, on, toggle] = useRefToggle(false);
<div>
<div>{on ? 'ON' : 'OFF'}</div>
<button ref={ref}>Toggle</button>
<button onClick={() => toggle(true)}>set ON</button>
<button onClick={() => toggle(false)}>set OFF</button>
</div>
);
};
License
MIT © Nghiep