What’s Next.js server actions

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() {
// …


This content originally appeared on DEV Community and was authored by ccsunny

Image description

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » What’s Next.js server actions." ccsunny | Sciencx - Saturday August 24, 2024, https://www.scien.cx/2024/08/24/whats-next-js-server-actions/
HARVARD
ccsunny | Sciencx Saturday August 24, 2024 » What’s Next.js server actions., viewed ,<https://www.scien.cx/2024/08/24/whats-next-js-server-actions/>
VANCOUVER
ccsunny | Sciencx - » What’s Next.js server actions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/24/whats-next-js-server-actions/
CHICAGO
" » What’s Next.js server actions." ccsunny | Sciencx - Accessed . https://www.scien.cx/2024/08/24/whats-next-js-server-actions/
IEEE
" » What’s Next.js server actions." ccsunny | Sciencx [Online]. Available: https://www.scien.cx/2024/08/24/whats-next-js-server-actions/. [Accessed: ]
rf:citation
» What’s Next.js server actions | ccsunny | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.