React `useForm`: `reset()` restores the last submitted values, not the initial ones
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Read packages/react/src/runtime/use-form.ts around the successful submitAction path and the reset() implementation, then check the useForm reset documentation. Decide how the API should restore the original values while preserving the current behavior for edit forms; done means create forms can reset to their initial values and the documented behavior matches the implementation.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version
void / @void/react 1.1.12
What happens
After a successful submit, useForm replaces its defaults with the submitted data (packages/react/src/runtime/use-form.ts, after submitAction returns ok):
const nextDefaults = { ...dataRef.current };
defaultsRef.current = nextDefaults;
setDefaultsState(nextDefaults);
So calling reset() after a successful submit restores the values that were just submitted. The docs describe reset(...fields) as "Reset form data to initial values", which suggests the values passed to useForm.
Reproduction
const form = useForm('/notes?create', { title: '', body: '' });
<form action={form.post}>
<input value={form.data.title} onChange={(e) => form.setData('title', e.target.value)} />
<button>Add</button>
</form>
- Type "Hello" and submit. The action succeeds.
- Call
form.reset(), for example from an effect onform.wasSuccessful. - Expected:
titleis''. Actual:titleis"Hello".
Why it matters
For "create" forms, clearing the fields after a successful submit is the most common need (add a note, add a todo, send a message). Today that requires keeping a separate copy of the original defaults outside useForm.
Promoting submitted values to defaults makes sense for "edit" forms (hasChanges goes back to false after saving), so I'm not suggesting that behavior should change, only that there should be a way to get back to the original values.
Possible fix
- a
resetOnSuccess: trueoption onuseForm, or - a way to reset to the original values, e.g.
reset({ initial: true })orresetToInitial().
At minimum, the reset() docs could say that submitted values become the new defaults after a successful submit.
- Ngôn ngữ chính
- TypeScript
- Star
- 402
- Fork
- 32
- Merge trung bình
- 10 giờ 18 phút
- Pull request đã merge (30 ngày)
- 113
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 voidzero-dev/void
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
voidzero-dev/void#529 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
voidzero-dev/void#428 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Auth config regeneration in dev can reuse a cached configCó thể đã có người làm @Brooooooklyn đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
voidzero-dev/void#550 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 46/100
voidzero-dev/void#547 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
voidzero-dev/void#546 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của voidzero-dev/void
Issue tương tự
-
native
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
prime-radiant-inc/evener#4839 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
processone/fluux-messenger#1790 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🛣️ Infrastructure
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
opencrvs/opencrvs-core#14232 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
kunchenguid/gh-axi#220 ·
Maintainer thường phản hồi trong vòng 1 ngày