This content originally appeared on DEV Community and was authored by ccsunny
What's server actions
Server action is async functions that runs on server
- async function
- runs on server
- can called in server component or client component
- can called in form or in useEffect
export default function HomePage() {
// Server Action
async function updateItemAction() {
'use server'
// Mutate data
}
return <form action={updateItemAction}>{/* ... */}</form>
}
Thinking on server action
since server action run on server, so it's provide a endpoint(POST) for other application to, but there is some issues we need to think
- how can we write API documentation for this endpoints? since we need to learn new concept like server actions, we need to think what's the point of this, personally I don's thinks this is a good way for browser to communicate with server but easy for react projects
This content originally appeared on DEV Community and was authored by ccsunny
ccsunny | Sciencx (2024-08-24T13:24:00+00:00) What’s Next.js server actions. Retrieved from https://www.scien.cx/2024/08/24/whats-next-js-server-actions/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
