react-use-bool
v1.0.0
Published
Simple React boolean hooks
Downloads
5
Maintainers
Readme
react-use-bool
Simple React boolean hooks
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>
)
}