reactjs / reactjs/react.dev

[Suggestion]: Document using Promises passed from RSC to the client without `use()`

Open
#7,810 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: documentation
Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

Summary

The docs on RSC should mention whether Promises passed from Server Components can be used without use().

Page

https://react.dev/reference/rsc/server-components

Details

Currently, the docs only discuss resolving Promises passed from the server using use(). Sometimes it can be useful to render a component with partial data and update its state once the promise is fulfilled. This appears to work.:

"use client";

export default function Component({ promise }) {
  const [data, setData] = useState(null);
  useEffect(() => {
    let canceled = false;
    promise.then((d) => !canceled && setData(d));

    return () => canceled = true;
  }, [promise])

  return (<p>{data}</p>);
}

However I can't find any mentions of this use case. I think that if this is officially supported, there should be an example showing how to do it. And if not, that should be explicitly stated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Server Components page at https://react.dev/reference/rsc/server-components and review its current discussion of Promises passed to client components. Determine whether the shown use case is officially supported, then document it with an example or explicitly state that it is unsupported. Done means the page addresses this use case clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.