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

Rename useFormState to useActionState #6776

Merged
merged 3 commits into from
Apr 25, 2024
Merged

Conversation

kassens
Copy link
Collaborator

@kassens kassens commented Apr 24, 2024

We renamed this and moved it to the react package because it's not tied to DOM forms.

@kassens kassens requested a review from rickhanlonii April 24, 2024 20:06
Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 9:25pm

Copy link

github-actions bot commented Apr 24, 2024

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]] 81.65 KB (🟡 +4 B) 185.56 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.

Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

Nice!! One thing is that we need to keep useFormState for a bit because it's only deprecated in 19 and there are a ton of users using it (for example, everyone on Next.js App Router) and there are links around the net for it. We could do that with a shell that has a warning and a link to the new page, or add a redirect in vercel.json

@@ -113,6 +113,7 @@ These Hooks are mostly useful to library authors and aren't commonly used in the
- [`useDebugValue`](/reference/react/useDebugValue) lets you customize the label React DevTools displays for your custom Hook.
- [`useId`](/reference/react/useId) lets a component associate a unique ID with itself. Typically used with accessibility APIs.
- [`useSyncExternalStore`](/reference/react/useSyncExternalStore) lets a component subscribe to an external store.
* [`useActionState`](/reference/react/useActionState) allows you to manage state of actions.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should there be a section Action Hooks maybe? Not sure where this should go.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I'd create a section with useTransition, useActionState, and useDeferredValue and call it like "UI hooks" or something

@@ -283,7 +281,7 @@ form button {

### My action can no longer read the submitted form data {/*my-action-can-no-longer-read-the-submitted-form-data*/}

When you wrap an action with `useFormState`, it gets an extra argument *as its first argument*. The submitted form data is therefore its *second* argument instead of its first as it would usually be. The new first argument that gets added is the current state of the form.
When you wrap an action with `useActionState`, it gets an extra argument *as its first argument*. The submitted form data is therefore its *second* argument instead of its first as it would usually be. The new first argument that gets added is the current state of the form.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A lot is referring to forms. Probably needs another pass to abstract this more from DOM forms specifically and explain how to use actions w/o forms.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, fwiw I was waiting to rewrite this before moving it here for that reason

@jackpope jackpope merged commit 4f55010 into reactjs:main Apr 25, 2024
5 checks passed
@koba04
Copy link
Member

koba04 commented May 2, 2024

@kassens Do you have a plan to add the isPending value returned from useActionState into the docs?

@rickhanlonii
Copy link
Member

@koba04 yeah I'm updating the docs, got a little delayed with React Conf

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.

5 participants