useToggle()
useToggle(
initialValue?): [boolean, () =>void]
Defined in: hooks/state/useToggle.ts:28
A custom React hook for managing a boolean toggle state. Provides the current value and a function to toggle it between true and false.
Parameters
initialValue?
boolean = false
The initial state of the toggle. Defaults to false.
Returns
[boolean, () => void]
An array containing:
value: The current boolean state.toggle: A function to toggle the state betweentrueandfalse.
Example
tsx
import { useToggle } from '@zl-asica/react';
const ToggleComponent = () => {
const [isOn, toggle] = useToggle(false);
return (
<div>
<p>The toggle is {isOn ? 'ON' : 'OFF'}</p>
<button onClick={toggle}>Toggle</button>
</div>
);
};