Skip to main content

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.