Skip to content

.tip

· one of the small things

use() reads a promise or a context, conditionally

use is the one hook you're allowed to call inside an if. Give it a promise and the component suspends until the promise resolves. Give it a context and it reads the context.

function Comments({ promise }: { promise: Promise<Comment[]> }) {
  const comments = use(promise);
  return <List items={comments} />;
}

Create the promise in a parent or on the server and pass it down. If you create it during render, you get a new one every time.

react