React Hooks
    Preparing search index...

    Function useBoolean

    • A simple and optimized React hook for managing boolean state.

      Parameters

      • defaultValue: boolean = false

        The initial boolean value.

        false
        

      Returns BooleanReturn

      An object containing the current value and helper methods.

      This hook uses React hooks internally:

      • useState — to store and manage the boolean state.
      • useCallback — to memoize helper methods.
      const { value, toggle, setTrue, setFalse, reset } = useBoolean();

      return (
      <>
      <p>{value ? 'ON' : 'OFF'}</p>
      <button onClick={toggle}>Toggle</button>
      <button onClick={setTrue}>Set True</button>
      <button onClick={setFalse}>Set False</button>
      <button onClick={reset}>Reset</button>
      </>
      );

      0.2.1