CLEANEST Way to write Next.js Server Actions ✨

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 64

  • @WebDevCody
    @WebDevCody 4 месяца назад +18

    Zsa let’s go!

  • @furkankaracan2076
    @furkankaracan2076 28 дней назад

    Thank you for your service sir

  • @chrschoeni
    @chrschoeni 4 месяца назад +2

    Amazing Videos for me to learn. I hope you make many more

  • @zakir.nuriiev
    @zakir.nuriiev 3 месяца назад

    Cool! Thank you for sharing such nice approach!

  • @finetopethiopia4095
    @finetopethiopia4095 4 месяца назад +2

    Amazing video, Lazar. One thing I noticed is, you are very comfortable working with NeoVim, but as someone like me who have never tried it, it is kinda confusing. Do you have a plan to record your videos using Vscode?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      Thank you! I would be a lot more descriptive to what I'm doing in a video than a live stream. If I'm going to a certain file I'd say it out loud, so even viewers who aren't using Neovim can understand what's going on and are able to follow along. Live streams are where I figure stuff out 😅 Appreciate the feedback though.

  • @loic299
    @loic299 2 месяца назад

    Hey Lazar, thanks a lot! Would you recommend using clean architecture infrastructure over the Server actions/ZSA approach? Or would using both be overkill? ZSA procedures already doing the controller job right? (Not to mention the fact that the framework is not decoupled from the interface layer)
    I need to expose my HTTP API, so I dlike to share the controllers functions/ZSA actions with both the HTTP API route handler and client components. Is it considered good practice to call ZSA actions from the API route handler? I also looked into IRPC, but I'm a bit lost. Is IRPC obsolete with server actions + ZSA/next-safe-action?
    Thank you so much for your help!

    • @nikolovlazar
      @nikolovlazar  2 месяца назад +1

      Glad you liked it! Treat the controllers as part of your core app’s logic, and everything framework-related as a “consumer”. You want all crucial logic like input validation and auth checks to be in your core app logic, so all consumers will function the same. Instead of calling a server function inside of an api handler, just call the controller in both places and handle the errors accordingly. That would be the smartest way to go about this.

  • @jacob_dmn
    @jacob_dmn 4 месяца назад

    amazing, appreciate your work.

  • @AmitErandole
    @AmitErandole 3 месяца назад +1

    I know this video wasn't about form validation. But I couldnt see rhe part where live client side validations were used from the zodschema with react hook form.
    Is there another video where you show us how client side validation with live errors are shown to the user?

    • @nikolovlazar
      @nikolovlazar  3 месяца назад +1

      You can see the definition above the "useServerAction" usage, but I actually created a gist for you: gist.github.com/nikolovlazar/824dd3efb67228f673e40494ed8e63a4. Hope this helps!

    • @AmitErandole
      @AmitErandole 3 месяца назад

      @@nikolovlazar this looks good. Very readable. Just a little confusion though. Where will the errors show up in the jsx? Is it the j component? Also shouldn't there be a onChange mode enabled on react hook form?

    • @nikolovlazar
      @nikolovlazar  3 месяца назад +1

      @@AmitErandole Yes it's the component. These components are from the shadcn/ui library. Here's how it's implemented if you want to replicate it, but don't want to use shadcn/ui: gist.github.com/nikolovlazar/a270127f8a3271a1d6db289030048b57. It's basically using the "useFormContext" hook that comes from "react-hook-form" to obtain the parent field state, in which the error is defined.

    • @AmitErandole
      @AmitErandole 3 месяца назад

      @@nikolovlazar great. Thank you so much for sharing this. Helps me connect the dots

    • @nikolovlazar
      @nikolovlazar  3 месяца назад +1

      @@AmitErandole Of course! I'm glad I can help!

  • @InekMarcinek
    @InekMarcinek 4 месяца назад

    Hey! Your videos really interested me on clean architecture. Do you recommend any books on that topic?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      That's great! I personally haven't read anything other than "Clean Code" and the "Gang of Four (GoF) Design Patterns". You can also ChatGPT it 😁

  • @Rajputana1974
    @Rajputana1974 4 месяца назад +1

    ZSA IS HERE 👍😅😊

  • @besuccessfull1891
    @besuccessfull1891 3 месяца назад +3

    So basically zsa is trpc but for server actions 😅

  • @semyaza555
    @semyaza555 4 месяца назад +1

    What’s the advantage of zsa over something like next-safe-action?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      I haven't used next-safe-action, but just by glancing at the docs it looks like it does the same job for the most part.

    • @semyaza555
      @semyaza555 4 месяца назад

      @@nikolovlazar 🙏 Thanks. Love this series btw.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      @@semyaza555 Thank you!

  • @bibblebabl
    @bibblebabl 4 месяца назад

    Thanks for the content! Can I clarify if it's possible to make a solid background without the light spot in the future? For some reason it's hard to read because of it

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      Absolutely! Thank you for the feedback 🙏

    • @bibblebabl
      @bibblebabl 4 месяца назад

      Thank you

  • @warisaremou8754
    @warisaremou8754 3 месяца назад

    Hi all I try zsa but request is still show in network and I can see the payload. It's the same in the zsa documentation. I though request are made on the server side. I'm using react not nextjs

    • @nikolovlazar
      @nikolovlazar  3 месяца назад

      server actions are executed on the server, but the client has to perform an HTTP call to invoke them. That's why you see it in the Network tab. that doesn't mean that the action was executed in the browser.

  • @HarisVFX
    @HarisVFX 4 месяца назад +1

    What are your thoughts on next safe actions?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      Haven't used it, but it's probably a decent library like ZSA.

  • @cabrelelvis
    @cabrelelvis 4 месяца назад

    It's very good I think, but why not separate the supabase logic in usecases for example, so that if you have to change bd or provider you won't need to touch your server actions which are already well structured

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      That’s what we’re doing! We’re still not done with the refactoring, but my goal is to isolate supabase and other elements of the stack into layers.

  • @interceptorghost1149
    @interceptorghost1149 3 месяца назад

    Hi buddy, could you provide your nvim config? It's pretty cool

    • @nikolovlazar
      @nikolovlazar  3 месяца назад

      Sure thing! github.com/nikolovlazar/dotfiles

  • @Mast3rDesign
    @Mast3rDesign 4 месяца назад

    great job Lazar

  • @bibblebabl
    @bibblebabl 4 месяца назад

    Have you tried next safe action btw? What is the difference?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      Haven't yet. I think for the most part the libraries are pretty much the same, but I haven't taken a better look at Next Safe Actions.

  • @Michelbouf
    @Michelbouf 4 месяца назад

    no way, brother where are the videos of the expense tracker app

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      Had to move them to a different channel: www.youtube.com/@lazars-streaming-archive. The React Native are coming tomorrow and Monday.

    • @Michelbouf
      @Michelbouf 4 месяца назад

      @@nikolovlazar thank you, I know those videos are long because are made in a Livestream mode, not like a course or tutorial, but I wonder if the app is completed after the last video? And if db room, mvvc, di, and other stuff like that is covered?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      The app is completed, but no DI or architecture or anything like that. There is a database though, so it is in a usable state.

  • @naylord5
    @naylord5 4 месяца назад

    🔥🔥🔥

  • @blazi_0
    @blazi_0 4 месяца назад +3

    Cool to know but man too much work, also I love how server actions turning into trpc slowly 😂

  • @nirmalscaria7258
    @nirmalscaria7258 4 месяца назад

    What is that IDE?

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +8

      This is my Neovim IDE! You like it? I can create a video on how I set the whole thing up, but my configuration is always changing so the video will get outdated pretty quickly. I do keep my config open source though:
      github.com/nikolovlazar/dotfiles
      Feel free to poke around and see how I configured neovim.

    • @crossmindedninja5522
      @crossmindedninja5522 4 месяца назад

      ​@@nikolovlazarpls make a video to setup exactly similar to yours

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      @@crossmindedninja5522 let's do it!

  • @zarock1044
    @zarock1044 4 месяца назад

    🤯 😍

  • @velinovleonid
    @velinovleonid 4 месяца назад

  • @clickbaitpolice9792
    @clickbaitpolice9792 2 месяца назад

    I don't understand why you would do all of this. The NextJS documentation already shows best practices for using server actions

    • @nikolovlazar
      @nikolovlazar  2 месяца назад

      You'll find yourself repeating a lot of code when you need to share common pre-exec logic between multiple actions. Think about authentication, input validation, analytics, instrumentation, etc... That's when using ZSA (and next-safe-action as well) shines. If you don't do those things, then using these libraries will most likely be an overkill.

  • @aberba
    @aberba 4 месяца назад +3

    Simply don't write serious backend code with server actions. Anything beyond basic usage will end up in a messy unmaintainable code.
    Next.js isn't suitable for a scalable backend application. Imagine doing RBAC, rate limiting, metering, heavy middleware actions, and load balancing with server actions or the route.js/ts setup.

    • @naylord5
      @naylord5 4 месяца назад

      I believe Vercel only recommend SA with specific use cases, i.e. mutations, like basic CRUD operations.
      But definitely is not a replace for an entire backend IMHO.

    • @nikolovlazar
      @nikolovlazar  4 месяца назад +1

      I believe Next.js isn't a one-size-fits-all solution, just like any other framework, but I'm curious to hear about where you hit the limits of it. In what use cases have you reached the limits of actions, but you couldn't get the job done? Not being sarcastic, I genuinely want to know 😁 this could be a really good discussion, and even a video topic!

    • @deftex55
      @deftex55 4 месяца назад

      @@nikolovlazar Exactly the same thing I was thinking about. When implementing something like that, even the clean architecture in Next.js feels wrong somehow, but it's working, and we have 0 problems. Maybe this is the future of web development: monolithic frameworks.

    • @TianYuanEX
      @TianYuanEX 4 месяца назад

      @@nikolovlazar ​Unrelated to the original comment about code scalability, but one problem Next.js has is that WebSockets & SSE don't work with it since you will deploy it to a serverless environment (unless you use a 3rd party solution like pusher for eg).
      As for the original comment, I think that if you organize your code well with good separation of concerns, it can allow you to go very far

    • @nikolovlazar
      @nikolovlazar  4 месяца назад

      @@TianYuanEX Yep, sockets are definitely out of question in a serverless environment. But there's definitely a way to keep a good code structure and not have (major) issues!