react-use-bool

1.0.0 • Public • Published

react-use-bool

Simple React boolean hooks

NPM version

How to use

react-use-bool
import {useBool, useToggle} from 'react-use-bool'
 
function Lamp() {
  const [on, turnOn, turnOff] = useBool()
 
  return (
    <div>
      <div>{on ? "ON" : "OFF"}</div>
      <button onClick={turnOn}>TURN ON</button>
      <button onClick={turnOff}>TURN OFF</button>
    </div>
  )
}
 
function ToggleLamp() {
  const [on, toggle, setValue] = useToggle(true)
 
  return (
    <div>
      <div>{on ? "ON" : "OFF"}</div>
      <button onClick={toggle}>TOGGLE</button>
      <button onClick={() => setValue(false)}>OFF</button>
    </div>
  )
}

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i react-use-bool

    Weekly Downloads

    1

    Version

    1.0.0

    License

    WTFPL

    Unpacked Size

    3.61 kB

    Total Files

    5

    Last publish

    Collaborators

    • farwayer