@d3vtool/use-boolean
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

useBoolean Hook

useBoolean is a custom React hook that helps manage boolean state with built-in actions to toggle or set the value directly. It simplifies the state management when working with boolean values and provides a clean and flexible API for handling state updates.

Installation

To install the useBoolean hook, you can use npm or yarn:

npm install @d3vtool/use-boolean
or
yarn add @d3vtool/use-boolean

Usage

Importing the hook and using

import React from 'react';
import useBoolean from "@d3vtool/use-boolean";

const ToggleComponent: React.FC = () => {
    const [state, actions] = useBoolean(false);

    return (
        <div>
            <p>The current state is: {state ? "True" : "False"}</p>
            <button onClick={actions.toggle}>Toggle State</button>
            <button onClick={() => actions.set(true)}>Set to True</button>
            <button onClick={() => actions.set(false)}>Set to False</button>
        </div>
    );
};

export default ToggleComponent;

Package Sidebar

Install

npm i @d3vtool/use-boolean

Weekly Downloads

2

Version

1.0.5

License

none

Unpacked Size

3.69 kB

Total Files

6

Last publish

Collaborators

  • ks961