[Mistakes]: Server Functions examples use incompatible action signatures

Đang mở
#8,537 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
74/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
javascript, react
Lĩnh vực
documentation

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.

Mô tả

type: typos
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 name state, so updateName(name) always receives ''.

  • On success, updateName returns undefined, but the client destructures {error} from its result.

  • When passed to <form action={updateName}>, React calls updateName with FormData, 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.

Ngôn ngữ chính
JavaScript
Star
11.8k
Fork
7.9k
Merge trung bình
16 giờ 6 phút
Pull request đã merge (30 ngày)
7

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của reactjs/react.dev

Tất cả issue của reactjs/react.dev

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.