-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Remove useMemo from useFormStatus example #6658
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size changes📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
I think I added this example and I don't recall why I didn't disable the input while submitting -- is there a reason why we changed that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty
) : null} | ||
</> | ||
<br /> | ||
<p>{pending ? `Requesting ${data?.get("username")}...`: ''}</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
<p>{pending ? `Requesting ${data?.get("username")}...`: ''}</p> | |
<p>{data ? `Requesting ${data.get("username")}...`: ''}</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense - out of curiosity, are pending
and data
always in sync?
@lunaleaps if you don't disable the input, then the user can continue typing but when the action finishes the reset will blow away their changes, which is sucky Screen.Recording.2024-02-24.at.10.34.28.AM.mov |
Overview
The useMemo here breaks the rules of React, is unnecessary and makes a worse experience:
showSubmitted
state is also unnecessary since thepending
state already tells you if it's being submitted.pending
andformData
values directly, the "Submitted request` text is tied directly to the form submission transition "pending" state, so the disabled state and the text update in the same commit.Additional improvements
I also made a couple more improvements:
Before
Screen.Recording.2024-02-23.at.11.50.59.AM.mov
After
Screen.Recording.2024-02-23.at.11.51.44.AM.mov