Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 473 Bytes

useToggle.md

File metadata and controls

24 lines (18 loc) · 473 Bytes

useToggle

React state hook that tracks value of a boolean.

useBoolean is an alias for useToggle.

Usage

import {useToggle} from 'react-use';

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

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