Next.js · Senior · Question 40 of 75

A component shows new Date().toLocaleString() and causes a hydration mismatch. What's the most correct fix?

Explanation

The server and the client are in different time zones and moments in time, so the string differs. Options: a client component that shows the time after mounting; formatting on the server with a fixed zone; suppressHydrationWarning on the element with the timestamp. Browser extensions also often cause mismatches.

Further reading

Problem with a question

Next.js · Senior · question 40

Test yourself

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

Take this quiz