Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 430 Bytes

useToggle.md

File metadata and controls

23 lines (17 loc) · 430 Bytes

useToggle

React state hook that tracks value of a boolean.

Usage

import {useToggle} from 'react-use';

const Demo = () => {
  const [on, toggle, set] = useToggle(true);

  return (
    <div>
      <div>{on ? 'ON' : 'OFF'}</div>
      <button onClick={toggle}>Toggle</button>
      <button onClick={() => set(true)}>set ON</button>
      <button onClick={() => set(false)}>set OFF</button>
    </div>
  );
};