useToggle()
The
useToggle() hook provides a simple way to manage boolean state. It returns the current state and a function to toggle it. The toggle function can also accept a specific boolean value to manually set the state.Import
typescript
Usage
Click the power button to toggle state. Use manual controls to set specific values.
System Off
Component.tsx
API
Arguments
initialValue– boolean (Optional) The initial state value. Defaults tofalse.
Returns
Returns a tuple containing:
[0] value– boolean The current state.[1] toggle– (value?: boolean) => void Function to update the state. Call without arguments to invert, or pass a boolean to set explicitly.