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