Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

React `useForm`: `reset()` restores the last submitted values, not the initial ones

未關閉
#523 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 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>
  1. Type "Hello" and submit. The action succeeds.
  2. Call form.reset(), for example from an effect on form.wasSuccessful.
  3. Expected: title is ''. Actual: title is "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: true option on useForm, or
  • a way to reset to the original values, e.g. reset({ initial: true }) or resetToInitial().

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,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

voidzero-dev/void 的其他 Issue

查看 voidzero-dev/void 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。