Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

[Suggestion]: Document that useFormStatus works with a preventDefault-ed onSubmit + startTransition

Ouverte Adaptée aux débutants
#8,682 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 3 jours

@Felix-ming y travaille déjà.

Depuis le 6/10/2026.

  • #8683 par @Felix-ming — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Documentation
Clarté
Clairement spécifiée
Activité
Active
Stack technique
javascript, react
Domaine
documentation

Piste de recherche

Mettez à jour la page de référence de useFormStatus à l’adresse react.dev/reference/react-dom/hooks/useFormStatus. Lisez les sections Returns et Usage, puis vérifiez la PR React liée et les cas de ReactDOMForm-test.js afin de confirmer les conditions décrites. Ajoutez l’explication de l’état en attente et un court exemple avec onSubmit/preventDefault()/startTransition ; le travail est terminé lorsque les deux appels requis et le comportement sont documentés avec exactitude.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

type: documentation
Summary

Document that useFormStatus also reports pending: true when a submit event handler calls event.preventDefault() and starts a Transition with startTransition, not only when the form uses the action prop.

Page

https://react.dev/reference/react-dom/hooks/useFormStatus

Details

I'm implementing a custom <Form> component that accepts a Transition-based prop like submitAction (it validates and transforms the values, then calls submitAction inside startTransition). I wanted to provide the form's pending state through useFormStatus itself, instead of adding a custom context. While investigating, I found that this already works, but because it is not documented, I could not tell whether it is safe to rely on.

The useFormStatus page currently describes the status only in terms of the action prop on the parent <form>. However, since https://github.com/facebook/react/pull/29019 (shipped in React 19.0.0), useFormStatus is also activated when startTransition is called inside a submit event handler that is preventDefault-ed:

After this change, useFormStatus will also be activated if you call startTransition(actionFn) inside a submit event handler that is preventDefault-ed.

The PR describes this as the way for UI component libraries to implement a custom action prop with onSubmit, and the behavior is covered by tests in ReactDOMForm-test.js:

This matters for form components like mine that cannot use the action prop, for example because they validate and transform values before calling the action, or because they do not want the automatic form reset.

I confirmed the behavior with React 19.3.0 in Chrome.

Playground: https://codesandbox.io/p/sandbox/custom-useformstatus-fm2fkl

// App.js
import { startTransition, useActionState } from "react";
import { useFormStatus } from "react-dom";

// A fake request that takes 2 seconds.
function save(value) {
  return new Promise((resolve) => setTimeout(() => resolve(value), 2000));
}

// A form component in a UI library. It does not use the `action` prop,
// e.g. because it validates and transforms the values before calling the action.
function MyForm({ submitAction, children }) {
  return (
    <form
      onSubmit={(event) => {
        event.preventDefault();
        const value = new FormData(event.currentTarget).get("name");
        startTransition(async () => {
          await submitAction(value);
        });
      }}
    >
      {children}
    </form>
  );
}

function SubmitButton() {
  const { pending } = useFormStatus();
  return (
    <button type="submit" disabled={pending}>
      {pending ? "Sending" : "Send"}
    </button>
  );
}

function App() {
  const [state, sendAction] = useActionState(async (prev, value) => {
    await save(value);
    return value;
  }, null);
  return (
    <MyForm submitAction={sendAction}>
      <input name="name" />
      <SubmitButton />
      {state && <p>Saved: {state}</p>}
    </MyForm>
  );
}

export default App;

pending stays true until the action finishes, and the form is not reset.

Suggested changes:

  • In "Returns", say that pending is also true while a Transition started from a preventDefault-ed submit event of the parent <form> is pending.
  • In "Usage", add a short example of the onSubmit + preventDefault() + startTransition pattern, and note that both preventDefault() and startTransition in the same event are required.
Langage dominant
JavaScript
Étoiles
11.8k
Forks
8k
Merge moyen
3 j 5 h
PR mergées (30 j)
9

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de reactjs/react.dev

Toutes les issues de reactjs/react.dev

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.