Next.js Discord

Discord Forum

Server action explanation why it is used and where

Answered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
I did not understand why server actions were used and how they were used before it was discovered.
for example in form we use Server action but we previously used form in an easy way without it. I read about that in the documentation , but doest not feel the concept of it.
Answered by Barbary Lion
Before you would create an API end point, and your form would call it. OR your form would be a client component.

Server action allows you to create a server side component (normally with no reactivity), and have a form execute some logic (normally it would ask an API to execute the logic, but server actions is now syntactic suger to allow this to happen)
View full answer

7 Replies

Barbary Lion
Before you would create an API end point, and your form would call it. OR your form would be a client component.

Server action allows you to create a server side component (normally with no reactivity), and have a form execute some logic (normally it would ask an API to execute the logic, but server actions is now syntactic suger to allow this to happen)
Answer
American black bearOP
Can you explain in more detail. if it is not a server component then also we can use fetch and the smae process than what is the differnece
Barbary Lion
When you use fetch, what are you doing ? You're calling an API endpoint you wrote ?
So you must write the API endpoint, and then call it using Fetch
Server action combines those 2 steps into 1
American black bearOP
Okay understood
Thank you for explaining