What's Next.js server actions
ccsunny
Posted on August 24, 2024
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
đź’– đź’Ş đź™… đźš©
ccsunny
Posted on August 24, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024