Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/netzo/deps/usehooks-ts.ts>useToggle

Full-stack Deno framework for building business web apps like internal tools, dashboards, admin panels and automated workflows.
Go to Latest
function useToggle
import { useToggle } from "https://deno.land/x/netzo@0.5.70/deps/usehooks-ts.ts";

Custom hook for managing a boolean toggle state in React components.

Examples

// Usage of useToggle hook 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.

Parameters

optional
defaultValue: boolean
  • The initial value for the toggle state.

Returns

[boolean, () => void, Dispatch<SetStateAction<boolean>>]

A tuple containing the current state, a function to toggle the state, and a function to set the state explicitly.