Prefer functional updates version in hooks documentation
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ả
Currently React hooks documentation at section Updating state is using a counter example for bot hooks and class based components. To recap:
In a class, we need to call this.setState() to update the count state:
<button onClick={() => this.setState({ count: this.state.count + 1 })}>
Click me
</button>
In a function, we already have setCount and count as variables so we don’t need this:
<button onClick={() => setCount(count + 1)}>
Click me
</button>
Although I can understand than this documentation must be simple and this example is really straightforward, isn't this a bad patter? Modifying state with a value based on old state?
The Functional update version is documented few pages after this example.
I'm wondering if:
- this example must be changed (although is probably the best type of example for state), or
- a warning box should be added to warn the user this is not the correct way to do.
To be more clear: I know there's nothing wrong with this specific example, but newcomers can quickly try to do something like calling setCount(count + 1) multiple times.
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 Updating state trong hooks-state.html và so sánh ví dụ về bộ đếm trong đó với phần Functional updates trong hooks-reference.html. Xác định xem ví dụ hay một cảnh báo giải thích sẽ đề cập tốt hơn đến các lần cập nhật lặp lại dựa trên state trước đó; hoàn thành khi tài liệu hướng dẫn rõ ràng cho người mới mà không mâu thuẫn với ví dụ hiện có.
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
- 45/100