If you answer yes, we store and analyse information that helps us improve the website. You can change your choice at any time at the bottom of the page. More about what we store and why.

We also store necessary information that cannot be opted out of. This makes the website work and keeps it secure.

Skip to main content

What are you looking for?

Try searching for…

useCheckboxGroup

A React hook to more easily handle a group of Checkbox components.

Usage

Below is a simple example of how to use the useCheckboxGroup hook to handle a group of Checkbox components.

In the getCheckboxProps function, the first parameter is value, which is a unique identifier for the option, or an object with props to be added to the Checkbox component.

If you pass an object, make sure it contains value.

Important: If you are going to pass props to a Checkbox, it is important that you pass them as objects to getCheckboxProps and not directly to the Checkbox. Otherwise, you risk overriding the functionality of useCheckboxGroup.


In response you get the object:

Allow indeterminate

When spreading getCheckboxProps on your Checkbox, you can pass allowIndeterminate: true to allow the checkbox to be in an indeterminate state.

Edit this page on github.com (opens in a new tab)