React `useForm`: `reset()` restores the last submitted values, not the initial ones
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 1-2 天
- 新手友好度
- 52/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- react, typescript
- 領域
- frontend
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- TypeScript
- 星號
- 402
- 分支
- 32
- 平均合併
- 10 小時 18 分鐘
- 30 天內合併 PR
- 113
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
voidzero-dev/void 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
voidzero-dev/void#529 ·
維護者通常 1 天內回覆
-
bug
難度 1/5 1-3 小時 新手友好度 78/100
voidzero-dev/void#428 ·
維護者通常 1 天內回覆
-
Auth config regeneration in dev can reuse a cached config可能已有人在做 @Brooooooklyn 今天認領。 未關閉
難度 4/5 3-5 天 新手友好度 35/100
voidzero-dev/void#550 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 46/100
voidzero-dev/void#547 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 38/100
voidzero-dev/void#546 ·
維護者通常 1 天內回覆
查看 voidzero-dev/void 的全部 Issue
相似的 Issue
-
数据界面的横向滚动条缺失未關閉
難度 2/5 1-3 小時 新手友好度 62/100
zilliztech/attu#1037 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
難度 2/5 1-3 小時 新手友好度 76/100
openclaw/openclaw#181212 · 1 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
apify/apify-mcp-server#1684 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
Automattic/data-liberation-agent#953 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
siteboon/claudecodeui#1642 ·
維護者通常 5 天內回覆