useToggle
Custom hook that manages a boolean toggle state in React components.
Installation
npx sse-hooks add use-toggle
yarn dlx sse-hooks add use-toggle
pnpm dlx sse-hooks add use-toggle
deno run -A npm:sse-hooks add use-toggle
bunx sse-hooks add use-toggle
Usage
example.ts
import { useToggle } from "./{hooks file}";
const [isToggled, toggle, setToggle] = useToggle(); // Initial value is false
// OR
const [isToggled, toggle, setToggle] = useToggle(true); // Initial value is true
// Use isToggled in your component, toggle to switch the state, setToggle to set the state explicitly.
API
Parameters
| Prop | Default | Type |
|---|---|---|
defaultValue | - |
The initial value for the toggle state. |
Returns
| Return Value | Default | Type |
|---|---|---|
[0] | - |
|
[1] | - |
|
[2] | - |
|
Types Aliases
No specific type aliases defined for this component.