useId
The React hook that generates a unique ID string that is stable across renders and matches between server and browser.
In more detail
Accessible components need IDs to link elements, for example aria-controls on a tab pointing at its panel's id. useId makes those IDs unique even when a component appears several times on a page.
Example
const id = useId(); <input id={`${id}-in`} aria-describedby={`${id}-hint`} />Related terms
- identifier — A name or number that picks out exactly one thing, such as one container, one image or one database row.
- aria-labelledby — An ARIA attribute that names an element using the text of one or more other elements, referenced by their id.
- compound component — A set of components designed to be used together, such as Tabs, Tabs.Trigger and Tabs.Panel, that share state behind the scenes.
- label element — The HTML element that names a form control; its for attribute (htmlFor in React) holds the control's id.
- ARIA — The W3C standard of HTML attributes, such as role and aria-expanded, that tell assistive technology what a custom widget is and what state it is in.
- hydration — The step where React in the browser attaches event handlers and state to HTML that was already rendered on the server.
Taught in
- Compound Component Patterns: Context Sharing & Internal State — Design Systems & Component Engineering
- Actionable Form Primitives: Buttons, Switches & Inputs — Design Systems & Component Engineering
- Creating Event Listener Hooks with Clean Teardown Logic — React 19 & Modern Component Architecture
- useId: Generating Stable Accessible Form Element Identifiers — React 19 & Modern Component Architecture