-
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
Fix server action code example #7202
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hi @IGassmann! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
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! 🙌 |
@@ -77,7 +77,7 @@ When the bundler builds the `EmptyNote` Client Component, it will create a refer | |||
|
|||
```js [[1, 2, "createNoteAction"], [1, 5, "createNoteAction"], [1, 7, "createNoteAction"]] | |||
"use client"; | |||
import {createNoteAction} from './actions'; | |||
import { createNoteAction } from './actions'; |
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.
Most of the code examples in the docs have spaces within the brackets.
"use client"; | ||
|
||
import {updateName} from './actions'; | ||
import { useState, useTransition } from 'react'; |
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.
Most of the code examples in the docs imports the used React functions.
|
||
function UpdateName() { | ||
const [name, setName] = useState(''); |
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.
The input wasn't using name
since it's an uncontrolled input.
} else { | ||
setName(''); |
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.
When the form submission succeeds, React already automatically resets the form. No need to reset manually the input value. However, we need to reset the error.
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.
"When the form submission succeeds, React already automatically resets the form." sorry where's that claim coming from? In the official docs there's an example doing formRef.current.reset();
, I guess exactly because it is not reset by default? (thought seeing the other mistakes there, it might be?).
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.
It comes from the docs as well.
I believe the example you mention resets the form manually because it's demonstrating optimistic behavior. If it didn't reset manually, it would have to wait for the request to complete for React to reset the form.
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.
Ah gotcha, thanks! I am just a passerby that was curious about the PR though, cannot review/approve/etc here, but looks good!
} | ||
}) | ||
} | ||
|
||
return ( | ||
<form action={submitAction}> | ||
<input type="text" name="name" disabled={isPending}/> | ||
{state.error && <span>Failed: {state.error}</span>} |
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.
state
didn't exist.
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.
this def was a LLM
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.
and a bad one at that
i still can't believe that LLM code did it to prod 😭😭😭😭 |
This fixes the code example in the "Composing Server Actions with Actions" section and updates the imports for all the code examples on the page to ensure consistency with the rest of the documentation.