The 3 REAL benefits of Next.js Server Actions

Поділитися
Вставка
  • Опубліковано 17 чер 2024
  • 👉 NEW React & Next.js Course: bytegrad.com/courses/professi...
    Hi, I'm Wesley. I'm a brand ambassador for Kinde (paid sponsorship).
    👉 Add authentication to your app FAST: bit.ly/3QOe1Bh
    👉 NEW React & Next.js Course: bytegrad.com/courses/professi...
    👉 Professional JavaScript Course: bytegrad.com/courses/professi...
    👉 Professional CSS Course: bytegrad.com/courses/professi...
    👉 Discord: all my courses have a private Discord where I actively participate
    🔔 Email newsletter (BIG update soon): email.bytegrad.com
    ⏱️ Timestamps:
    0:00 Old way
    2:04 New way
    3:08 API route
    4:10 First benefit: Server Action
    6:00 Under the hood
    6:57 Second benefit: useFormStatus & useOptimistic
    9:44 Third benefit: Progressive enhancement
    #webdevelopment #programming #coding

КОМЕНТАРІ • 49

  • @ByteGrad
    @ByteGrad  20 днів тому +1

    My Professional React & Next.js course is OUT NOW now! Find it here: bytegrad.com/courses/professional-react-nextjs -- this is the #1 resource to master the latest React & Next.js, my absolute best work.

  • @TheGrandChieftain
    @TheGrandChieftain 9 місяців тому +15

    Server actions might make the actual request simpler, but React Query seems a lot better for managing the state of your fetch requests.

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

    This is the second video I have watched on this channel and I am already in love. The explanations are really clear and on point. Top level content!

    • @ByteGrad
      @ByteGrad  9 місяців тому

      Awesome, thank you!

  • @psyferinc.3573
    @psyferinc.3573 8 місяців тому +1

    your doing well man. im glad you joined the scene

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

    Thanks for your video and explanation! It's helpful to me!

  • @matthiasmatanda4295
    @matthiasmatanda4295 4 місяці тому

    Thank you sir for this short video with very important information that I needed to hear.

  • @user-pf1uk8py3r
    @user-pf1uk8py3r 4 місяці тому +1

    Thanks for your clear explanation! ❤

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

    This is exactly what I was looking for. Thanks.

  • @ianc6418
    @ianc6418 6 місяців тому +1

    another great class. thank you

  • @martg0
    @martg0 4 місяці тому +1

    very interesting! clear explanation 👏 Would this apply for a datagrid too?

  • @spas.z.spasov
    @spas.z.spasov 7 місяців тому

    Hello, thank you for the tutorials. What I'm searching for for complex form validation - i.e. a tutorial that puts together the 1) server actions + 2) react-hook-form + 3) zod.

  • @NeilGebhard
    @NeilGebhard 9 місяців тому +2

    Appreciate the way you explain things

  • @dawid_dahl
    @dawid_dahl 6 місяців тому +1

    Subscribed to this channel so hard! 👌🏻

  • @phsopher
    @phsopher 10 місяців тому +3

    Helpful explanation thanks! Does this only work for forms? Suppose I just want to have a single button that does something, e.g., liking a comment on a social media site. Should I go through the whole process of wrapping it in a form, then making the button a separate child component etc. Seems easier to just make an api endpoint and call it on onClick. Or is there a more Nextonic (a word I just made up) way?

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

      Yes, works outside forms too but you have to invoke the server action differently (not with ‘action’ attribute)

  • @saidibra9231
    @saidibra9231 9 місяців тому +5

    can you please make a video between Next.js and Express.js and which one to choose in the back-end and the benefits and cons of each one

    • @ByteGrad
      @ByteGrad  9 місяців тому

      Good idea

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

      Nextjs has a decent backend, but between Express and Nextjs for backend, I prefer "Nestjs". This last one is a JS backend framework that uses express but is opinionated, I recommend it with close eyes.

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

      Having used nestjs for one medium large project - would not recommend. Way overkill for most projects and makes some simple things way too labour intensive.

  • @hibachouchene
    @hibachouchene Місяць тому +1

    Best explanation on UA-cam 🤩

  • @jorden123
    @jorden123 10 місяців тому +4

    Thanks for your video and explanation!
    From a DevOps perspective... you are creating a monolith application, which you can not scale the front and the back separately, I guess this is the biggest downside. The other big downside is that you can not use multiple clients (front-ends) and using the same server (back-end).

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

      turborepo? you create reusable components for each client (assuming they all use typescript/javascript)

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

      Yeah that is what I am not a fan of server action. There are made to be used by your nextjs front ONLY.

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

    So on the surface it may seem simpler but in practice it still makes the same number of network trips and now you have to deal with NextJS and having client vs server components. BTW, you can easily abstract away the fetch calls inside utility classes (eg, api.todos.add(value)). It's a nice way to separate the concerns.

  • @AnkitSharma-mu3oj
    @AnkitSharma-mu3oj 9 місяців тому

    In previous video you told importing something inside "use client" component then whatever is imported also runs on client side ?

  • @mahdimotallebi7207
    @mahdimotallebi7207 8 місяців тому +1

    Thank you

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

    Good explanation

  • @alexnelson2119
    @alexnelson2119 5 місяців тому +1

    I've really been enjoying server actions. Nice not to have to make an api route. One thing I found out recently that's a bit annoying with respect to form data is there are no actual boolean type values you can get from HTML forms. Checkboxes only have 'on' when checked and no value at all if unchecked. Also, input forms always have string values when you get their value from formData, never a number, even if the input is type=number. Of course you can always do a combo of state and server actions.

  • @SR-zi1pw
    @SR-zi1pw 11 місяців тому +1

    Nice comparison

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

    can we use server actions for sign in , currently using action='/auth/sign-in' with method = 'post' where my sign-in route.ts in in app/auth/sign-in/route.ts?

  • @boyywnkobe
    @boyywnkobe 9 місяців тому

    is it work only for app folder ?

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

    When are you releasing you Next Js course?

    • @ByteGrad
      @ByteGrad  9 місяців тому

      It’s super close. Make sure you’re subscribed to the email newsletter :)

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

    what if we have server in node and from there, we are storing cookies to browser and using in server components, so I am not possible
    get access of cookies to node server. is there any way?

  • @yigitardaunsal7269
    @yigitardaunsal7269 10 місяців тому

    what is the name of vs code theme?

  • @stevebendersky2056
    @stevebendersky2056 9 місяців тому

    How do you reset the form without using useState for each input field?

    • @MrBrandenS
      @MrBrandenS 9 місяців тому

      Well if you need the whole form reset, html forms have a reset method for wiping out inputs.

  • @learner8084
    @learner8084 Місяць тому

    I'm confused. Do I use React Hook Forms or use Server Actions ? Does React Hook Forms also use server action ? If I use React Hook Forms, I give up the benefit of server actions ? Any advice any one ? Thanks very much in advanced.

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

    what's the diffirent with php

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

    Thanks, how do I do it with dashboard and get data? outside of forms

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

      Best to use fetch in a server component to get data

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

    am I the only one who thinks "progressive enhancment" is bs ?

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

      Yes 😂

    • @ray-lee
      @ray-lee 7 місяців тому +2

      Yes

    • @gubocci
      @gubocci 6 місяців тому +1

      Yes

    • @Sube_Gordas
      @Sube_Gordas 5 місяців тому +1

      Yes

    • @loveboat
      @loveboat 4 місяці тому

      Useful in 0.0001% of cases and has a fancy name