react-checkbox-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.13 • Public • Published

react-checkbox-hook

NPM CI codecov JavaScript Style Guide

A React hook to easily work with checkboxes

Example | Demo

Features

  • Controllable API
  • Headless (Bring-your-own-UI)
  • Checkboxes nesting
  • Support of indeterminate checkboxes
  • Small size and no dependencies

Install

yarn add react-checkbox-hook
npm install --save react-checkbox-hook

Quickstart

Learn more in example
CodeSandbox

import React from 'react';
import { useCheckbox } from 'react-checkbox-hook';

const App = () => {
  const options = [
    { id: 0, title: 'Option 1' },
    { id: 1, title: 'Option 2' },
    { id: 2, title: 'Option 3' },
  ];
  const { selectedOptions, handleOptionChange } = useCheckbox({ options });

  return (
    <div>
      {options.map((option) => (
        <div key={option.id}>
          <label>
            <input
              type="checkbox"
              checked={selectedOptions.includes(option.id)}
              onChange={(e) => handleOptionChange(option, e.target.checked)}
            />
            {option.title}
          </label>
          <br />
        </div>
      ))}
    </div>
  )
}

License

MIT © rostyk-begey


This hook is created using create-react-hook.

Package Sidebar

Install

npm i react-checkbox-hook

Weekly Downloads

1

Version

1.0.13

License

MIT

Unpacked Size

12.9 kB

Total Files

7

Last publish

Collaborators

  • rostyk-begey