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 useFormState reference #6338

Merged
merged 4 commits into from
Oct 25, 2023
Merged

Conversation

davidmccabe
Copy link
Contributor

@davidmccabe davidmccabe commented Oct 5, 2023

Initial stab at docs for useFormState. The examples are limited as we don't have server actions actually working within the docs website yet.

This is another example I could include which uses a client action to update the state of the component, but I think it's confusing. If we want people to refresh instead of updating client state, maybe we shouldn't show this. https://codesandbox.io/s/strange-waterfall-wqwsys?file=/App.js

Preview

@github-actions
Copy link

github-actions bot commented Oct 5, 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.82 KB (-7 B) 182.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.

src/content/reference/react-dom/hooks/useFormState.md Outdated Show resolved Hide resolved
src/content/reference/react-dom/hooks/useFormState.md Outdated Show resolved Hide resolved
src/content/reference/react-dom/hooks/useFormState.md Outdated Show resolved Hide resolved
src/content/reference/react-dom/hooks/useFormState.md Outdated Show resolved Hide resolved
src/content/reference/react-dom/hooks/useFormState.md Outdated Show resolved Hide resolved
"devDependencies": {}
}
```
</Sandpack>
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered adding an example demonstrating how you could use useFormState to update the UI without JavaScript?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how to demonstrate that without having RSC on the docs website, do you have an idea of how that would look?

Copy link
Contributor

Choose a reason for hiding this comment

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

You could add a non-interactive example with standard Markdown code syntax e.g. ```js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there some specific application or use case for updating the UI without javascript that is different from existing examples such as Add to Cart?

Copy link
Contributor

@mattcarrollcode mattcarrollcode left a comment

Choose a reason for hiding this comment

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

I've only looked and commented on the first half. Overall I think there needs to be some changes from describing how the API should be used to what the API does and how it works. I think the usage section is the right place to describe how to solve problems with the API. I think all the sections above the usage section should be focused on what the API does and how it work, and less on use-cases and opinions on how the API should be used.

src/sidebarReference.json Show resolved Hide resolved

<Intro>

`useFormState` is a Hook that allows you to read the return value of the form action after a form is submitted.
Copy link
Contributor

Choose a reason for hiding this comment

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

read the return value of the form action

I think "return value of the form action" it a lot for folks that are new to this to parse. Have you considered making this more descriptive/abstract? I think the less React-specific langauge we can use here the easier its going to be for folks new to forms with React to understand the rest of the page.

after a form is submitted.

I don't think this is quite right. You can trigger a formAction from a button that doesn't actually submit the form: https://codesandbox.io/s/stoic-fog-qnyvn7?file=/App.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to "useFormState is a Hook that allows you to update state based on the result of a form action." — what do you think?

@sophiebits
Copy link
Member

Can we make the real-world examples of the action function more prominent? Right now you need to scroll all the way to the recipes and click actions.js to see even a full simple example of an action.

Copy link
Member

@acdlite acdlite left a comment

Choose a reason for hiding this comment

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

I think this is good enough to merge in its current state, but we can keep iterating. Just don't want it to be blocked once you do decide to merge.

```json package.json hidden
{
"dependencies": {
"react": "experimental",
Copy link
Member

Choose a reason for hiding this comment

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

This can just be "canary" now

@davidmccabe davidmccabe merged commit 5e40d13 into reactjs:main Oct 25, 2023
3 checks passed
@sophiebits
Copy link
Member

@davidmccabe thoughts on my comment above for a follow-up?

@davidmccabe
Copy link
Contributor Author

I accidentally merged this without the commit where I incorporate the feedback here. Trying to figure out how to fix it now.

@sophiebits
Copy link
Member

ah, great! feel free to ping me on work chat if I can help you get out of a git pickle

@davidmccabe
Copy link
Contributor Author

Merged the PR with the intended changes #6383

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.

10 participants