Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 757 Bytes

useToggle.md

File metadata and controls

36 lines (25 loc) · 757 Bytes

useToggle

A hook to toggle a boolean value.

Arguments

  • defaultValue (boolean): The initial boolean value.

Returns

  • An array containing:
    • The current boolean value.
    • A function to toggle the value.

Hooks Involved

How to Use

import useToggle from "./useToggle"

export default function ToggleComponent() {
    const [value, toggleValue] = useToggle(false)

    return (
        <div>
            <div>{value.toString()}</div>
            <button onClick={toggleValue}>Toggle</button>
            <button onClick={() => toggleValue(true)}>Make True</button>
            <button onClick={() => toggleValue(false)}>Make False</button>
        </div>
    )
}