Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#523 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@0froq ya está trabajando en esto.

Desde el 23/10/2026.

  • #568 de @0froq — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
52/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
react, typescript
Área
frontend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
402
Forks
32
Merge medio
8 h 32 min
PR fusionados (30 d)
111

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de voidzero-dev/void

Todos los issues de voidzero-dev/void

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.