Give an example when componentWillMount can be called multiple times
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the linked React blog post and the referenced Stack Overflow question, then inspect the relevant documentation page for the async-rendering lifecycle guidance. The work is complete when the documentation includes a practical example showing how componentWillMount can be invoked multiple times and clearly explains the resulting usage concern.
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