Explain why componentDidMount is a better place to make an ajax request
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ả
In the docs, in componentWillMount section section it says:
Avoid introducing any side-effects or subscriptions in this method
And in the componentDidMount section:
If you need to load data from a remote endpoint, this is a good place to instantiate the network request
Which for me is confusing because I won't like to wait for the component to be mounted to dispatch an ajax call to fulfill the component data dependencies. I would like to do it as soon as possible, like in the constructor, not even in componentWillMount.
Clearly you may have a reason why you say this in the docs, I might be not seeing the bigger picture. So it will be nice if you can explain a bit more in detail or point me in the direction of where I can find the reason.
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
Đọc các phần được liên kết về componentWillMount và componentDidMount trong tài liệu React, cùng với phần hướng dẫn xung quanh về vòng đời. Làm rõ lý do tài liệu khuyến nghị bắt đầu các yêu cầu từ xa trong componentDidMount và giải đáp mối lo ngại về việc phải chờ đến khi mount; issue được hoàn thành khi hướng dẫn về thời điểm và lý do đã rõ ràng.
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ó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- 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
- 38/100