DEV Community

ccsunny
ccsunny

Posted on

1

What's Next.js server actions

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>
}
Enter fullscreen mode Exit fullscreen mode

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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay