Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#8,682 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@Felix-ming đang làm issue này rồi.

Từ ngày 6/10/2026.

  • #8683 của @Felix-ming — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, react
Lĩnh vực
documentation

Hướng nghiên cứu

Cập nhật trang tham khảo useFormStatus tại react.dev/reference/react-dom/hooks/useFormStatus. Đọc các phần Returns và Usage, sau đó kiểm tra PR React được liên kết và các trường hợp trong ReactDOMForm-test.js để xác nhận các điều kiện được mô tả. Bổ sung phần giải thích về trạng thái đang chờ và một ví dụ ngắn với onSubmit/preventDefault()/startTransition; hoàn tất khi cả hai lời gọi bắt buộc và hành vi được ghi lại chính xác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
JavaScript
Star
11.8k
Fork
8k
Merge trung bình
2 ngày 31 phút
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của reactjs/react.dev

Tất cả issue của reactjs/react.dev

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.