Hint
Generates stable unique IDs that are consistent between server and client — for accessibility attributes
useId generates a stable, unique ID that is consistent across server-side rendering and client-side hydration.
// ❌ Problem — random or Math.random IDs cause SSR hydration mismatch
function Field({ label }) {
const id = Math.random(); // different value on server vs client → hydration error!
return (
<>
>
);
}
// ✅ useId — stable, unique, SSR-safe
function Field({ label }) {
const id = useId(); // e.g. ":r0:", ":r1:" — consistent server + client
return (
<>
>
);
}
// Multiple IDs from one useId call — append suffixes
function ComboField() {
const id = useId();
return (
<>
Your full name
>
);
}