reactjs / reactjs/react.dev

Give an example when componentWillMount can be called multiple times

未關閉
#2,566 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先閱讀連結的 React 部落格文章和所引用的 Stack Overflow 問題,接著檢視相關文件頁面中關於 async-rendering 生命週期的指引。當文件包含一個實際範例,展示 componentWillMount 可能被呼叫多次,並清楚說明因此產生的使用疑慮時,工作便完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript, react
領域
documentation
Issue 類型
文件
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。