React 18 concurrent instantiation and disposal
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 11.8k
- 派生
- 7.9k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 11
描述
Hi there!
I have been reflecting on what React 18 concurrent mode means for instantiation and disposal of objects returning state.
So something you could do before React 18 and StrictMode was:
const SomeComponent = () => {
const ref = useRef()
if (!ref.current) {
ref.current = new SomeStateToAccessInComponentRender()
}
useEffect(() => {
return () => ref.current.dispose()
}, [])
}
But as I understand, with React 18 (spearheaded by StrictMode) you can not really rely on creating instances during "rendering" cause React might call the function body multiple times ,and even abandon it, before mounting and running any effects.
I understand that pure components are necessary for concurrent mode and to me it makes a lot of sense that React is becoming this pure state synchronisation using subscriptions type of implementation. But what does not make sense to me is that there is no way to "create something" when React has the intention of mounting a component and "dispose that something" when React is abandoning the component due to concurrent mode or unmounting it.
I wish there was some explicit documentation/statement that explains you can not rely on React 18 to control the instantiation and disposal of objects and more importantly some guides to how you should actually deal with it.
Which brings me to... have I gotten it wrong? Is there a way to safely do this? And if not, do we now rely on external state stores to determine when to instantiate/dispose of objects?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
没有指定文件或测试。先从 issue 中关于 React 18、concurrent-rendering 和 StrictMode 的示例开始,然后审阅现有的、关于 render-time instantiation、effects 和 disposal 的文档。完成的标准是添加明确的指导,说明这种模式是否安全,以及对象应如何创建和释放。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- documentation, frontend
- Issue 类型
- 文档
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100