Give an example when componentWillMount can be called multiple times
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 11.8k
- Fork
- 7.9k
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 11
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách đọc bài đăng blog React được liên kết và câu hỏi Stack Overflow được tham chiếu, sau đó xem trang tài liệu liên quan để biết hướng dẫn về vòng đời async-rendering. Công việc hoàn tất khi tài liệu bao gồm một ví dụ thực tế cho thấy componentWillMount có thể được gọi nhiều lần và giải thích rõ ràng mối lo ngại về việc sử dụng phát sinh từ đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, react
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100