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

Update 02-server-actions-and-mutations.mdx #64248

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ export function addItem() {
Defining a Server Action inside a component creates a [closure](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures) where the action has access to the outer function's scope. For example, the `publish` action has access to the `publishVersion` variable:

```tsx filename="app/page.tsx" switcher
'use client'
export default function Page() {
const publishVersion = await getLatestVersion();

Expand All @@ -928,11 +929,12 @@ export default function Page() {
...
}

return <button action={publish}>Publish</button>;
return <button onClick={publish}>Publish</button>;
Copy link
Contributor

@AhmedBaset AhmedBaset Apr 12, 2024

Choose a reason for hiding this comment

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

@samcx
onClick passes MouseEvent param not FormData. formAction was correct

Copy link
Member

Choose a reason for hiding this comment

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

@A7med3bdulBaset Thanks for the correction, will update!

}
```

```jsx filename="app/page.js" switcher
'use client'
export default function Page() {
const publishVersion = await getLatestVersion();

Expand All @@ -944,7 +946,7 @@ export default function Page() {
...
}

return <button action={publish}>Publish</button>;
return <button onClick={publish}>Publish</button>;
}
```

Expand Down