@biggerpixel/use-bool-state
v1.0.1
Published
Custom React Hook for boolean state
Downloads
10
Readme
useBoolState
Usage
npm i @biggerpixel/use-bool-state
import useBoolState from '@biggerpixel/useboolstate';
const Component = () => {
const [isOpen, toggleIsOpen, setIsOpen] = useBoolState(false); // setIsOpen *optional if you want to set a specific value
return (
<div>
{/* Use Boolean State */}
{isOpen && <h1>Hello World!</h1>}
{/* Toggle Boolean State with ease */}
<button onClick={toggleIsOpen}>Toggle Title</button>
{/* Set Boolean State with specific value */}
<button onClick={() => setIsOpen(true)}>Toggle Title</button>
<button onClick={() => setIsOpen(false)}>Toggle Title</button>
</div>
);
};