[Suggestion]: Document using Promises passed from RSC to the client without `use()`
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 11.8k
- 派生
- 7.9k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 11
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 https://react.dev/reference/rsc/server-components 的 Server Components 页面开始,查看其中当前关于传递给 client components 的 Promises 的讨论。确定所示用例是否得到官方支持,然后通过示例对其进行说明,或明确说明它不受支持。当页面清楚地说明这一用例时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100