State preconfigured to do everything you could want with a boolean value.
const MyComponent = () => { const [open, handlers] = useBoolean(false); return ( <> <Button onClick={handlers.toggle}>Toggle</Button> <Button onClick={handlers.on}>Open</Button> <Button onClick={() => { handlers.set(Math.random() < 0.5); }}>Random</Button> {open && <Button onClick={handlers.off}>Close</Button>} </> );} Copy
const MyComponent = () => { const [open, handlers] = useBoolean(false); return ( <> <Button onClick={handlers.toggle}>Toggle</Button> <Button onClick={handlers.on}>Open</Button> <Button onClick={() => { handlers.set(Math.random() < 0.5); }}>Random</Button> {open && <Button onClick={handlers.off}>Close</Button>} </> );}
boolean or function that returns a boolean
tuple with current state and an object with state setters
Generated using TypeDoc
State preconfigured to do everything you could want with a boolean value.
Example