[Mistakes]: Server Functions examples use incompatible action signatures
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ả
Summary
The updateName Server Function is defined as updateName(name), but the page later uses it as a direct form action and with useActionState. These usages pass different arguments, so the examples cannot work with the shown function.
Page
https://react.dev/reference/rsc/server-functions
Details
The page defines:
export async function updateName(name) {
if (!name) {
return {error: 'Name is required'};
}
await db.users.updateName(name);
}
There are several inconsistencies/mistakes:
-
In “Server Functions with Actions”, the input does not update the
namestate, soupdateName(name)always receives''. -
On success,
updateNamereturnsundefined, but the client destructures{error}from its result. -
When passed to
<form action={updateName}>, React callsupdateNamewithFormData, not a string. -
When passed to
useActionState, React calls it with(previousState, FormData), and it must consistently return the next state.
The examples should define a Server Function with the correct parameters and return value for each usage.
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 trang tham chiếu Server Functions tại https://react.dev/reference/rsc/server-functions và so sánh ví dụ updateName giữa “Server Functions with Actions”, hành động form trực tiếp và cách sử dụng useActionState. Được xem là hoàn tất khi các tham số và giá trị trả về của mỗi ví dụ khớp với cách React gọi nó, bao gồm các đối số FormData và trạng thái trướ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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 74/100