controllable state hook

A hook that lets one component work both controlled and uncontrolled, using the parent's value when given and its own state otherwise.

In more detail

It checks whether a value prop such as checked was passed. If so it defers to it and only calls onCheckedChange; if not it stores state itself, starting from defaultChecked. Consumers get one API for both modes.

Related terms

Taught in

References