Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#524 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
67/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
frontend

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
402
Forks
32
Avg merge
10h 51m
Merged PRs (30d)
100

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from voidzero-dev/void

All issues in voidzero-dev/void

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.