Create a Server

My Problem with Next.js Server Actions

My Problem with Next.js Server Actions

#Problem #Next.js #Server #Actions

“James Q Quick”

I spent hours trying to get loading states to work with Server Actions. Here’s what I learned about how to fix it along with a few other tips and gotchas.

Server Actions –

Thanks to Xata and Sentry for sponsoring my time to work on Deals for Devs!

Try Xata –
Try Sentry –

**Newsletter**
Newsletter 🗞 –

**DISCORD**
Join the Learn Build Teach Discord Server 💬 –

Follow me on Twitter 🐦 –
Check out the Podcast –
Courses –

**QUESTIONS ABOUT MY SETUP**
Check out my Uses page for my VS Code setup, what recording equipment I use, etc.

source

 

To see the full content, share this page by clicking one of the buttons below

Related Articles

16 Comments

  1. I think it makes more sense if you think of the form as a context provider. The useFormStatus can't be used above the context of the form, and as others have mentioned what if you had multiple forms on one page? Also its honestly a better way to to code it anyways since your form stays mostly server side and and your submit button can now be reused in any form component and it'll just work. Definitely a bit annoying though if you don't know the rules. Gonna need some eslint rules to help with things like this I think

  2. I went through that same issue few weeks ago. its really a weird design decision and as you said they probably have a reason for this. it is what it is, but this is when I always have the impression that Remix do things better.

  3. you can put that actions file inside your app directory using the app router, it doesn't need to be in the root. I ended up using a dedicated actions file per view, which created a "model view controller" like structure.

Leave a Reply