use-ref-toggle

0.1.1 • Public • Published

use-ref-toggle

NPM version NPM yearly download

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

Readme

Keywords

Package Sidebar

Install

npm i use-ref-toggle

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

5.89 kB

Total Files

5

Last publish

Collaborators

  • nghiepit