• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    TypeScript
  • Created over 10 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sensible checkbox groups manipulation for DOM.

React-checkbox-group

Greenkeeper badge Build Status

This is your average checkbox group:

<form>
  <input
    onChange="{handleFruitChange}"
    type="checkbox"
    name="fruit"
    value="apple"
  />Apple
  <input
    onChange="{handleFruitChange}"
    type="checkbox"
    name="fruit"
    value="orange"
  />Orange
  <input
    onChange="{handleFruitChange}"
    type="checkbox"
    name="fruit"
    value="watermelon"
  />Watermelon
</form>

Repetitive, hard to manipulate and easily desynchronized. Lift up name and onChange, and give the group an initial checked values array. See below for a complete example

Install

npm install react-checkbox-group

or

yarn add react-checkbox-group

Simply require/import it to use it:

import CheckboxGroup from 'react-checkbox-group'

Example

import React, { useState, useEffect } from 'react'
import CheckboxGroup from 'react-checkbox-group'

const Demo = () => {
  // Initialize the checked values
  const [fruits, setFruits] = useState<string[]>(['apple', 'watermelon'])

  useEffect(() => {
    const timer = setTimeout(() => {
      setFruits(['apple', 'orange'])
    }, 5000)

    return () => clearTimeout(timer)
  }, [])

  return (
    <CheckboxGroup name="fruits" value={fruits} onChange={setFruits}>
      {(Checkbox) => (
        <>
          <label>
            <Checkbox value="apple" /> Apple
          </label>
          <label>
            <Checkbox value="orange" /> Orange
          </label>
          <label>
            <Checkbox value="watermelon" /> Watermelon
          </label>
        </>
      )}
    </CheckboxGroup>
  )
}

ReactDOM.render(<Demo />, document.body)

License

MIT.

More Repositories

1

react-github-api-project

Project using use React + React Router + GitHub API for DecodeMTL
JavaScript
59
star
2

wordpress-api-nextjs-theme

A workshop on creating a WordPress theme with React and Next.js for WordCamp Montreal
43
star
3

hw-parallax

Hardware-accelerated parallax scrolling plugin for jQuery
JavaScript
39
star
4

node-express-reddit-clone

Build a Node, Express and MySQL-based clone of Reddit for DecodeMTL web development bootcamp
JavaScript
29
star
5

dogecoin-snap

Non-EVM chain tutorial for MetaMask Snaps: create a Dogecoin wallet
TypeScript
10
star
6

hardhat-starter

My opinionated Hardhat starter for Encode Club's bootcamp
Solidity
9
star
7

underscore-async-templates

AJAX-loaded underscore templates with added include functionality
JavaScript
7
star
8

react-conditional-component

This component displays its children only if they satisfy their predicate
JavaScript
7
star
9

snappy-recovery

πŸ’₯ Snapy Recovery: Social recovery for MetaMask wallets
TypeScript
7
star
10

react-intro-workshop

React intro workshop for DecodeMTL
6
star
11

metamask-snaps-transaction-insights-workshop

Providing transaction insights with MetaMask 🦊 Snaps
TypeScript
6
star
12

react-pizza-project

Learn React by building a pizza ordering app, for DecodeMTL bootcamp
JavaScript
6
star
13

react-router-example

DecodeMTL Web Development Bootcamp
JavaScript
6
star
14

reddit-nodejs-api

DecodeMTL workshop to connect NodeJS to MySQL
JavaScript
4
star
15

decodemtl

Repo for DecodeMTL's site
HTML
4
star
16

webapis-workshop

Workshop for Free Code Camp Montreal!
HTML
3
star
17

mobx-matchmedia

A MobX observable for window.matchMedia
TypeScript
3
star
18

react-boilerplate

This is my take on a React boilerplate.
CSS
3
star
19

siwe-metamask-snap

Example of SIWE from a dapp to a snap
TypeScript
2
star
20

fullstack-practice-project

Fullstack practice project for DecodeMTL bootcamp
2
star
21

oop-game-project

Fix the bugs, and then customize this game while learning about Object-Oriented programming in JavaScript!
JavaScript
2
star
22

reddit-clone-frontend-workshop

DecodeMTL
1
star
23

reddit-cli-project

Project to create a command-line Reddit clone :)
JavaScript
1
star
24

babel-jest-require-ensure

Make require.ensure work with jest and babel-jest
JavaScript
1
star
25

docker-nodejs-devel

Installs nodejs-devel on ubuntu
Shell
1
star
26

decodemtl-wp-frontend

DecodeMTL site
JavaScript
1
star
27

foundation-skeleton

Zurb Foundation 5 skeleton
CSS
1
star
28

react-intro-possible-solutions

DecodeMTL Web Development Bootcamp
JavaScript
1
star
29

real-world-array-methods

1
star
30

snapquanow

TypeScript
1
star
31

dashboardly-frontend

Front-end for fullstack project at DecodeMTL
JavaScript
1
star
32

ziad-saab.github.io

My personal webpage
HTML
1
star
33

react-derived-state-demo

Created with CodeSandbox
JavaScript
1
star