Explanation on what can go wrong if Hooks were called inside loops or nested functions?
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ả
The Rules of Hooks section states that the first rule of Hooks is to only call hooks at the top level, i.e. "Don’t call Hooks inside loops, conditions, or nested functions". Later in the section, it explains what happens if we put a Hook call inside a condition. This still leaves me with some questions/doubts though. Are there examples where something can go wrong if Hooks were:
- called inside a loop?
- called inside a nested function? Furthermore, isn't a custom hook just a nested function? 🤔
I've tried to dig into some related questions on Stack Overflow here and here, but the answers provided only give the correct examples, but not the incorrect ones.
Could you provide incorrect examples for the other two cases? Or at least a little bit clarification would be most appreciated. :)
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 với phần Rules of Hooks, đặc biệt là phần giải thích hiện có về các lần gọi Hook có điều kiện. Thêm các ví dụ sai hoặc phần làm rõ về Hooks trong vòng lặp và các hàm lồng nhau, bao gồm cả cách custom Hooks khác biệt, và coi công việc là hoàn tất khi các trường hợp này được giải thích rõ ràng trong tài liệu.
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ó
- 3/5
- Thời gian dự kiến
- 1-2 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
- 45/100