React · Senior · Question 6 of 75

Which code in render typically causes a hydration error?

Explanation

The server and the client must render the same HTML. Time, random numbers, checking window, localStorage and the browser locale produce different results. Show client-only values after mounting (an effect or useSyncExternalStore with getServerSnapshot). For unavoidable text differences (a timestamp) there's suppressHydrationWarning.

Further reading

Problem with a question

React · Senior · question 6

Test yourself

Take the React · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz