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 working with server actions blog #303

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

yunusemreozdemir
Copy link
Contributor

No description provided.

Copy link

linear bot commented Oct 31, 2024

Copy link

vercel bot commented Oct 31, 2024

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

Name Status Preview Updated (UTC)
website ✅ Ready (Inspect) Visit Preview Nov 4, 2024 10:43am

}
```

2. Server Action is then passed down to a Client Component so that it can be used with `onClick`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't get what we mean here

Maybe we should switch the places of the two code snippets here

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 elaborated it a little bit:

  1. Event handlers such as onClick cannot be used in Server Components. Therefore we need to separate the Button as a Client Component and pass the clap Server Action down to it.


**Choosing an Approach**

As shown in the design with Client Components, you can also use Server Actions to fetch data. However, this is discouraged since actions only use the `POST` method. For this case, fetching the data in React Server Components and passing it down as props seems to be a better design. Moreover, this approach provides a unified simple view of the component and displays the data on first render instead of using `useEffect`.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a source for

However, this is discouraged since actions only use the POST method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Data Fetching and Caching in Next.js Documentation primarily uses React Server Components for data fetching. It contains no examples with Server Actions. Also Server Actions and Mutations in Next.js Documentation hints that they are intended to be used to handle form submissions and data mutations. Following statement is also from this documentation:

Behind the scenes, actions use the POST method, and only this HTTP method can invoke them.

I don't find it necessary to include these resources, do you recommend any changes?

data/blog/2024-11-01-server-actions.mdx Outdated Show resolved Hide resolved
data/blog/2024-11-01-server-actions.mdx Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants