Intermediate React Interview QuestionsIntermediateConcept
React · Question 61
What is useId used for in React?
Direct answer
useId generates a stable identifier that is useful for connecting accessibility attributes such as a label to an input across client and server rendering.
PasswordField.jsx
function PasswordField() {
const hintId = useId();
return (
<>
<input
type="password"
aria-describedby={hintId}
/>
<p id={hintId}>Use at least 12 characters.</p>
</>
);
}The main use case is accessibility relationships and generated IDs that need to be safe across React's rendering model.