use-toggle

v4.7.0arrow_drop_down
v4.7.0
STATUS
Passing
DOWNLOADS
215
VISIBILITY
Public
PUBLISHED
6 years ago
SIZE
4 KB
1 contributor
Install use-toggle as a package?
Copied
npm i @bit/giladshoham.react-hooks.use.use-toggle
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
chevron_left
chevron_right

useToggle

React state hook that tracks value of a boolean.

useBoolean is an alias for useToggle.

Usage

import {useToggle, useBoolean} 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>
  );
};
Help and resources