React useId in 2026: Why It Beats Math.random() for Accessibility and SSR Hydration
This article was written with the assistance of AI, under human supervision and review.
Most React developers reach for Math.random() when they need a unique ID. The component renders, the form field gets an ID, the label connects, and everything works. Ship it.
Then the production SSR logs fill with hydration warnings. Screen readers stop announcing field relationships. The client DOM re-renders on every page load, flickering inputs and breaking focus states. Users file accessibility bugs, and the team scrambles to find the root cause.
The problem is not random IDs themselves. The problem is that Math.random() runs twice in server-side rendering: once on the server, once on the client. Two separate JavaScript runtimes produce two different values for the same component instance.…