[Bug]: Example given in "Handling return values in forms" section for "use-server" docs fails to compile
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, react
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu với phần “Handling return values in forms” được liên kết trên trang use-server và so sánh ví dụ useActionState của phần đó với tài liệu useActionState được liên kết. Cập nhật ví dụ requestUsername để các đối số của nó khớp với chữ ký action được ghi trong tài liệu, sau đó xác minh rằng ví dụ trong tài liệu biên dịch được.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
The following example is given in Handling return values in forms section for "use server" docs, fails to compile.
// requestUsername.js
'use server';
export default async function requestUsername(formData) {
const username = formData.get('username');
// ..
}
// UsernameForm.js
'use client';
import { useActionState } from 'react';
import requestUsername from './requestUsername';
function UsernameForm() {
const [state, action] = useActionState(requestUsername, null, 'n/a');
// ..
}
Page
https://react.dev/reference/rsc/use-server#handling-return-values
Details
It fails to compile because, as per the useActionState docs,
useActionState(action, initialState, permalink?)
the "action" (requestUsername in this case) should have previousState as the first argument,
and formData as the second argument.
However, for the above example, the requestUsername action has formData as the first argument,
rather than previousState. Therefore, it fails to compile.
The following is the correct way mentioned in the useActionState docs:
async function increment(previousState, formData) {
return previousState + 1;
}
function StatefulForm({}) {
const [state, formAction] = useActionState(increment, 0);
// ..
}
I can raise a PR for the fix, if it's okay.
- 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
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.
Issue khác của reactjs/react.dev
-
type: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
bug: unconfirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
type: typos
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
bug: unconfirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100