React `useForm`: add `onSuccess` / `onError` callbacks
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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de voidzero-dev/void
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
voidzero-dev/void#529 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
voidzero-dev/void#428 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 56/100
voidzero-dev/void#527 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 54/100
voidzero-dev/void#525 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 1-2 días Aptitud para principiantes 52/100
voidzero-dev/void#523 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de voidzero-dev/void
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
phivk/rubiks-lab#33 ·
Los mantenedores suelen responder en 1 día
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedPosiblemente ocupada @ManyaJain111 la tomó hoy. Abiertobug enhancement possible-duplicate
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
AOSSIE-Org/PictoPy#1637 · 4 comentarios ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
chaitin/MonkeyCode#1437 ·
Los mantenedores suelen responder en 1 día
-
rtdb-info-connected-order test: unhandled 'connection is closed' rejection fails the CLI suiteAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
area:cards enhancement migration ready-for-agent
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
fil-donadoni/tolaria#6309 ·
Los mantenedores suelen responder en 1 día