Error Handling in Server Actions Next.js (Incl. Toasts!)

Поділитися
Вставка
  • Опубліковано 9 січ 2025

КОМЕНТАРІ •

  • @ByteGrad
    @ByteGrad  7 місяців тому +1

    👉 NEW React & Next.js Course: bytegrad.com/courses/professional-react-nextjs

  • @naylord5
    @naylord5 10 місяців тому +5

    Thank God I found your channel, the content is pure gold.
    Thank you so much for sharing your knowledge with the community!
    Cheers mate! 🍻

    • @ByteGrad
      @ByteGrad  10 місяців тому +1

      Much appreciated!

  • @simonsmashup
    @simonsmashup Рік тому +2

    This approach is mind blown. I didn't think about having the server actions in a sperate functions in the page. Great video! Saved my day!

  • @investandcyclecheap4890
    @investandcyclecheap4890 Рік тому +4

    Great video! I stumbled across this video because I wanted to show messages to the client from my server actions. There is not much out there right now for how to handle situations like these, so thanks for sharing!

  • @alanwilliamduarte5617
    @alanwilliamduarte5617 Рік тому +4

    thank you so so much for this, i was completly lost and thought I would have to use client components for absolutely everything. Thanks for this video

  • @webdevmix
    @webdevmix 8 днів тому +1

    Love your teaching style! This was really helpful!

  • @editdev
    @editdev Рік тому +5

    thank you! i was using throw new Error() from the server component and it worked locally, then broke as soon as I deployed it. This is a much better way of handling errors 👍

  • @aurorasofie
    @aurorasofie Рік тому +5

    Love your tutorials. Using them alot while learning next 13. You deserve more subs!

  •  9 місяців тому +1

    Greatest explanation about error handling in React and Toasts! Thanks a lot!!

  • @joaobebber
    @joaobebber 10 місяців тому +1

    Came here from Brazil! You helped me too much, thanks a lot! 🎉

  • @ofwoodfalegnameria1107
    @ofwoodfalegnameria1107 7 місяців тому +1

    Like always the most comphrensive tutorial in the web. Tanks a lot

  • @HarshitPrasad-n8e
    @HarshitPrasad-n8e 11 місяців тому +1

    yet another informative and detailed solution. Thanks a bunch

  • @LeeWalpole
    @LeeWalpole 11 місяців тому +1

    Your content is bang on every time. Perfect pace and crystal clear! Thanks so much. This way is leagues better than the version ChatGPT suggested 🙏

  • @dawid_dahl
    @dawid_dahl Рік тому +1

    Thank you so much! Will most probably use this in my production app at work.

  • @hashcode01
    @hashcode01 2 місяці тому +2

    Is there a way to use a global error middleware in server actions, similar to the approach used in Express or Hono?

  • @dog4ik
    @dog4ik Рік тому +12

    Wow that really sucks, we need to be able to handle errors in catch block of server action

    • @DaanBiesterbos
      @DaanBiesterbos 2 місяці тому

      You can? In both places. To handle both serverside and clientside logic accordingly?

  • @hydrognspa8753
    @hydrognspa8753 7 місяців тому +1

    Ok. I'll hit that subscribe button. You totally deserve it :')

  • @stephenpaul7499
    @stephenpaul7499 10 місяців тому +2

    Thanks for the video :)
    Is there a way to have a global error handler set up to handle all server action errors? I tried an ErrorBoundary in a component marked with "use client" but was unsuccessful.

  • @weichen3994
    @weichen3994 Рік тому +1

    exactly what i was looking for ty!

  • @umernasir4217
    @umernasir4217 Рік тому +1

    Great Content!

  • @vignesh_m_1995
    @vignesh_m_1995 7 місяців тому

    For Client Side Validation, we get the FormData only during Submit (inside the action). What if we need to do the validation immediately while updating a text field (blur)?? Storing the form fields in the local component state becomes necessary right. Also other features like for pre-filling the form on load showing the fields below based on a dropdown selection needs the data to be stored on the local state like the usual react component right?. Or is that any other way for it?

  • @codinginflow
    @codinginflow Рік тому

    React's useFormState hook is kind of a shorthand to do the same thing

    • @ByteGrad
      @ByteGrad  Рік тому

      True, I published this video before that hook came on the scene. Still, that hook has quite some boilerplate / confusing way of working IMHO

    • @codinginflow
      @codinginflow Рік тому +1

      @@ByteGrad I see! I like your videos, keep it up!

  • @santiskiffa
    @santiskiffa 6 місяців тому

    great video, love it !
    am really struggling with specific field erros (using Zod for example 'hours cannot be zero'). vs more generic errors ('this client already exists in db'). how to return errors what to do on the client side and what on the server .. how to reset the errors . if there can ever be a video on that it would save me :)

  • @liu-river
    @liu-river Рік тому +2

    How do I do this if I want to use the transition hook? I can't seem to get the response on client side from my server action.

    • @liu-river
      @liu-river Рік тому +3

      Nevermind, I figured it out, I can get the error inside the startTransition callback.

  • @ПетрКраснопир
    @ПетрКраснопир 10 місяців тому

    Why we need return error from server action catch? Can we use try catch in clientAction handler, and do all the same, but in catch, not in result.error condition?

  • @jawyor-k3t
    @jawyor-k3t 2 місяці тому

    But simply returning errors would still give 200 status code, no? Wouldn't that make our endpoints awkward, returning OK status while containing errors? Is that something I should worry about?

  • @tarunkhubchandani5869
    @tarunkhubchandani5869 5 місяців тому

    Sir, error boundary (error.jsx) doesn't catch errors occuring in event handlers invoking server actions in client components ?

  • @Milotiiic
    @Milotiiic 11 місяців тому

    What if your app has several languajes? you can't just get the message from the error because it will always be in english, or worse: you may be displaying weird errors to the client like "unexpected < in JSON" or the typical "whatever is not a function"

  • @programmingwithnit5308
    @programmingwithnit5308 Рік тому +1

    Thank you so much 🎉❤

  • @amershboul9107
    @amershboul9107 7 місяців тому +1

    oh mannn!! you're the best!!

  • @kevinpruett
    @kevinpruett Рік тому +1

    Great work

  • @tawsifhaque9360
    @tawsifhaque9360 Рік тому

    what vs code theme do you use?

  • @alexlykesas9733
    @alexlykesas9733 8 місяців тому

    I was wondering, Why not throw the error? and handle it with try catch?

  • @kayodionizio2886
    @kayodionizio2886 11 місяців тому +1

    Useful!!!!

  • @manoval1000
    @manoval1000 Рік тому +1

    this is gold

  • @hongz1
    @hongz1 8 місяців тому

    Nextjs dev team needs to add special return command syntax so that there won’t be “consistent return” eslint error.

  • @codedusting
    @codedusting 6 місяців тому

    This whole react-server-component fails totally the moment it meets the real world. It's nothing but a bad DX with no improvements whatsoever. What exactly do we achieve with this pattern when the client-side JS is anyways being shipped the moment we do "use client"?

    • @DaanBiesterbos
      @DaanBiesterbos 2 місяці тому

      The server action is not shipped. How does it fail?

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 6 місяців тому

    thank you so much

  • @AdarshRadhakrishna
    @AdarshRadhakrishna Рік тому

    good one

  • @ГлебЗикунов-ъ1з
    @ГлебЗикунов-ъ1з Рік тому +1

    Thanks a lot!