useReducer dispatch flow clarification
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ả
Hi,
I've been looking around to try to find out more about the "dispatch / render" flow and can not find anything relevant yet.
My question is: when I do 2 dispatchsequentially such as:
dispatch({type: ACTION_1});
dispatch({type: ACTION_2});
Are we sure that the 2 actions will be processed before the next rendering cycle occurs?
Could it be that on the next rendering cycle, only ACTION_1 has been processed then ACTION_2 is processed on a later rendering cycle?
In other words, from the react perspective, is doing:
dispatch({type: ACTION_1});
dispatch({type: ACTION_2});
equivalent to:
dispatch({type: ACTIONS: payload: [ACTION_1, ACTION2]});
In a small demo, it seems that it doesn't matter:
https://codesandbox.io/s/tzp0s (see the console messages)
In my larger react app, it seems that often time there is a render cycle between 2 consecutive dispatch.
Is it considered an anti-pattern to do 2 dispatch sequentially and should we instead do 1 dispatch with the content of the 2 dispatch combined?
Thank you!
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
Không có tệp tài liệu hoặc test nào được nêu tên. Hãy bắt đầu bằng cách tái hiện hành vi dispatch tuần tự trong CodeSandbox được liên kết và so sánh với hành vi của ứng dụng lớn hơn đã mô tả; công việc được xem là hoàn tất khi đã xác định được hướng dẫn React liên quan, đồng thời làm rõ mối quan hệ giữa dispatch và render cũng như cách sử dụng được khuyến nghị.
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, frontend
- 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
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100