Next.js · Middle · Question 63 of 75

With Cache Components, how do you keep new Date() out of the static shell?

async function CurrentTime() {
  await io()
  return <p>{new Date().toISOString()}</p>
}

Explanation

'use cache' captures the value once for everyone. io() suspends during prerendering; unlike connection(), it doesn't block prefetching.

Further reading

Problem with a question

Next.js · Middle · question 63

Test yourself

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

Take this quiz