-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
} | ||
``` | ||
|
||
2. Server Action is then passed down to a Client Component so that it can be used with `onClick`. |
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.
I didn't get what we mean here
Maybe we should switch the places of the two code snippets here
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.
I elaborated it a little bit:
- Event handlers such as
onClick
cannot be used in Server Components. Therefore we need to separate theButton
as a Client Component and pass theclap
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`. |
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.
can we add a source for
However, this is discouraged since actions only use the
POST
method
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.
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?
No description provided.