Skip to content

QuizNot attempted

Fixing a client-only value

You need to show the user's local time without a hydration error. Best fix?
export default function ViewedAt() {
return <span>Viewed at: {new Date().toLocaleTimeString()}</span>;
}
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Render a placeholder first, then set the time in useEffect (two-pass rendering)
  • Effects run only on the client after hydration, so render a placeholder that matches the server HTML, then set the real time in useEffect (two-pass rendering).
  • Not 'use server': that marks Server Actions, it doesn't make rendering client-only.
  • Not Suspense: nothing suspends
  • the mismatched value still renders on both sides.
  • Not useMemo: it still runs during render on both server and client, giving different strings.
  • Alternatives: dynamic(..., { ssr: false }), or suppressHydrationWarning for an intentional, harmless mismatch.