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

React `useForm`: add `onSuccess` / `onError` callbacks

Abierto
#524 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start by reading the useForm implementation in use-form.ts and find where wasSuccessful, errors, and error are set inside the action. Check how the form's state and submission lifecycle are handled, then add callbacks through the options described in the issue. Done means success and error callbacks run for the corresponding outcomes while the existing typed form state remains available.

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

Descripción

Version

void / @void/react 1.1.12

Problem

In React, form.post / put / patch / delete are form actions built on useActionState (#141), so they can't be awaited. That leaves no direct way to run code when a submit finishes, for example to:

  • show a toast ("Note added"),
  • clear the form (see #523),
  • move focus back to the first field,
  • navigate or close a dialog.

Today this has to be done by watching state in an effect:

const form = useForm('/notes?create', { title: '', body: '' });
const wasPending = useRef(false);

useEffect(() => {
  const settled = wasPending.current && !form.pending;
  wasPending.current = form.pending;
  if (settled && form.wasSuccessful) {
    toast.success('Note added');
  }
}, [form.pending, form.wasSuccessful]);

This is easy to get wrong. Watching wasSuccessful alone isn't enough, because it stays true until the next submission, so the effect has to track pending to detect each submit finishing.

Switching to action() works because it can be awaited, but then you lose useForm's typed data, field errors and pending.

Proposal

Callbacks in the useForm options, similar to Inertia's useForm:

const form = useForm(
  '/notes?create',
  { title: '', body: '' },
  {
    onSuccess: () => {
      form.reset();
      toast.success('Note added');
    },
    onError: (errors) => {
      /* validation errors or VoidActionError */
    },
  },
);

They could be called from inside the action in use-form.ts, right where wasSuccessful / errors / error are set today.

Lenguaje dominante
TypeScript
Estrellas
402
Forks
32
Merge medio
10 h 51 min
PR fusionados (30 d)
100

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.