Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useFormStatus Hook API reference documentation #6314

Merged
merged 4 commits into from
Oct 17, 2023
Merged

Conversation

mattcarrollcode
Copy link
Contributor

@mattcarrollcode mattcarrollcode commented Sep 23, 2023

Add initial reference documentation for the useFormStatus Hook

Preview: https://react-dev-git-useformstatus-fbopensource.vercel.app/reference/react-dom/hooks/useFormStatus

@github-actions
Copy link

github-actions bot commented Sep 23, 2023

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

One Page Changed Size

The following page changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/[[...markdownPath]] 78.8 KB (🟡 +26 B) 182.75 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@lunaleaps lunaleaps marked this pull request as ready for review October 7, 2023 16:44
@lunaleaps
Copy link
Contributor

@mattcarrollcode @kmiddleton14 @davidmccabe @TheSavior PR is ready for another look!

Copy link
Contributor

@kmiddleton14 kmiddleton14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comments and clarification questions but overall lgtm!

The `useFormStatus` Hook provides status information of the last form submission.

```js [[1, 5, "status.pending"]]
import action from './actions';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we're importing action from ./actions vs. getting it from useFormStatus()? What're the differences between the action returned from useFormStatus() vs. using the imported one and when to use one over the other

Copy link
Contributor

@lunaleaps lunaleaps Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The action prop that is given in useFormStatus is the action we're passing to the <form> tag. If we didn't pass an action in <form action={action}... then status.action would be null

import action from './actions';

function Submit() {
const status = useFormStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we use the same convention as earlier?
const { pending } = useFormStatus();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally replaced this with the object as I wanted to mirror the definition that useFormStatus returns status information, more than just pending.

True, it's cleaner to use {pending} but my impression is that this version puts less emphasis on the other properties that are returned in status -- but just slightly. So happy to change if you strongly disagree.


* `pending`: A boolean. If `true`, this means the parent `<form>` is pending submission. Otherwise, `false`.
* `data`: An object implementing the [`FormData interface`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) that contains the data the parent `<form>` is submitting. `null` if there is no active submission or no parent `<form>`.
* `method`: A string value of either `'get'` or `'post'`. This represents whether the parent `<form>` is submitting with either `GET` or `POST` [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). By default, a `<form>` will use `GET` method and can be specified by the [`method`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attributes_for_form_submission) property.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch! Updating

}
```
</Sandpack>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to include a usage example for method and/or action too from useFormStatus?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I was wondering the same but I can't think of common patterns in which you'll need to reference the method and even more so the action prop. If you have any ideas, happy to add!

@lunaleaps lunaleaps merged commit 90ca701 into main Oct 17, 2023
3 checks passed
@lunaleaps lunaleaps deleted the useFormStatus branch October 17, 2023 22:33
@mattcarrollcode
Copy link
Contributor Author

Thank you @lunaleaps getting this done! This looks great. I love the troubleshooting section and the accessing form data example. I didn't even know about the data property!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants