Uh oh!
There was an error while loading. Please reload this page.
Remove useMemo from useFormStatus example - #6658
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size changesDetails📦 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! 🙌 |
lunaleaps
commented
Feb 23, 2024
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? |
Uh oh!
There was an error while loading. Please reload this page.
| ) : null} | ||
| </> | ||
| <br /> | ||
| <p>{pending ? `Requesting ${data?.get("username")}...`: ''}</p> |
There was a problem hiding this comment.
Nit
| <p>{pending ? `Requesting ${data?.get("username")}...`: ''}</p> | |
| <p>{data ? `Requesting ${data.get("username")}...`: ''}</p> |
There was a problem hiding this comment.
Makes sense - out of curiosity, are pending and data always in sync?
rickhanlonii
commented
Feb 24, 2024
@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:
showSubmittedstate is also unnecessary since thependingstate already tells you if it's being submitted.pendingandformDatavalues 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