@zal-kit/react
v1.0.1
Published
A collection of useful React hooks for modern web applications
Downloads
179
Maintainers
Readme
@zal-kit/react
A collection of useful React hooks for modern web applications.
Requirements
This package requires the following peer dependencies:
react>= 16.8.0react-dom>= 16.8.0
Installation
npm install @zal-kit/react
# or
yarn add @zal-kit/react
# or
pnpm add @zal-kit/reactHooks
useToggle
A simple hook for managing boolean state with a toggle function.
import { useToggle } from '@zal-kit/react';
function MyComponent() {
const [isOpen, toggle, setIsOpen] = useToggle(false);
return (
<div>
<button onClick={toggle}>Toggle</button>
<button onClick={() => setIsOpen(true)}>Open</button>
{isOpen && <div>Content</div>}
</div>
);
}API:
initialValue(boolean, optional): Initial state value (default:false)- Returns:
[state, toggle, setState]state: Current boolean valuetoggle: Function to toggle the statesetState: Function to set state directly
TypeScript
This package is written in TypeScript and includes type definitions.
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Publishing
To publish a new version:
# Update version
npm version patch # or minor, major
# Publish to npm
npm publish