1.0.13 • Published 4 months ago

react-checkbox-hook v1.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

react-checkbox-hook

NPM CI codecov JavaScript Style Guide

A React hook to easily work with checkboxes

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.

1.0.13

4 months ago

1.0.9

4 months ago

1.0.8

4 months ago

1.0.11

4 months ago

1.0.10

4 months ago

1.0.12

4 months ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago