Give an example when componentWillMount can be called multiple times
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 11.8k
- 派生
- 7.9k
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 11
描述
I've found such phrase on this page https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html about componentWillMount callback:
The above code is problematic for both server rendering (where the external data won’t be used) and the upcoming async rendering mode (where the request might be initiated multiple times).
The same problem is described for componentWillUpdate and componentWillReceiveProps.
If I'm not mistaken it means that this function can be executed multiple times for one component if I use async rendering. I've found such question on StackOverflow: https://stackoverflow.com/questions/54533907/react-componentwillupdate-getting-called-twice about the same problem. I think I understand theoretical possibility of case when componentWillMount will be called twice: it can happen when mouning and initial rendering of some component was interrupted with higher priority task, so mounting restarts and calls componentWillMount again. Unfortunately neither documentation nor StackOverflow has any practical example of code which cause multiple calls of componentWillMount.
I've tried to make such an example myself using experimental React.JS version but has no luck.
I think it's better to have such an example to allow people who is not an expert in React.JS source code to under problem of such lifetime callbacks usage. I understand that it's an experimental feature and it can be changed in future but it's easier to understand the conception of async rendering when you have practical examples of possible problems.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读链接的 React 博客文章和所引用的 Stack Overflow 问题,然后查看相关文档页面中关于 async-rendering 生命周期的指导。文档包含一个实际示例,展示 componentWillMount 如何被多次调用,并清楚说明由此产生的使用问题后,工作即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100