React · Senior · Question 53 of 75

Why does this component suspend forever (or refetch endlessly)?

function Profile({ id }) {
  const user = use(fetch(`/api/users/${id}`).then((r) => r.json()));
  return <h1>{user.name}</h1>;
}

Explanation

After suspending, React re-renders the component, which creates another promise. Pass a promise from a Server Component, a data library or a cache keyed by id.

Further reading

Problem with a question

React · Senior · question 53

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