Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#523 2 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@0froq já está trabalhando nisso.

Desde 23/10/2026.

  • #568 de @0froq — aberto

Avaliação

Dificuldade
4/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
52/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
react, typescript
Domínio
frontend

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
TypeScript
Estrelas
402
Forks
32
Merge médio
8h 32min
PRs com merge (30d)
111

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de voidzero-dev/void

Todas as issues de voidzero-dev/void

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.