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
- controlled component — A component whose state, such as whether it is open or checked, is passed in by its parent, which also handles changes.
- uncontrolled component — A component that keeps its own state internally, optionally starting from a default such as defaultOpen or defaultChecked.
- React hook — A function whose name starts with use, such as useState or useEffect, that lets a React component keep state or run side work.
Taught in
- Headless Architecture: State vs Presentation Separation — Design Systems & Component Engineering