How To Use Next.js 14 Server Actions

Поділитися
Вставка
  • Опубліковано 20 сер 2024

КОМЕНТАРІ • 106

  • @3J2A3Y
    @3J2A3Y 8 місяців тому +11

    As a beginner, I can say that reading the Nextjs docs is overwhelming but when they get explained - like you did. It makes perfect sense.

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

    This is the best explanation I have watched so far, you have earned a new subscriber. Thanks!

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

    Perfect explanation about the server actions.

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

    Never seen a better explanation than this 💯

  • @fahdfady6632
    @fahdfady6632 7 місяців тому +2

    Amazing, it all makes sense now.

  • @user-zn3fg1eg4m
    @user-zn3fg1eg4m 6 місяців тому +1

    Hi this tutorial is really explanatory and can be understand well than other video on the same topic. There is a miner suggestion i want to add that it will be more beneficial to have a get or fetch data actions too.

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

    Wow. You explained it all. Thx

  • @NOTHING-en2ue
    @NOTHING-en2ue 9 місяців тому +1

    now i really understand the server-actions, very well tutorial thanks a lot ❤

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

    Thanks for sharing Brett.

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

      You are welcome!

    • @dev-akeel
      @dev-akeel 9 місяців тому

      Sharing is caring.
      But when I shared something with Brett. Bro got angry at me and is not talking to me now😢

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

    Well done. Keep up the good work!

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

    You always know what we need

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

      Glad I could read your mind

    • @dev-akeel
      @dev-akeel 9 місяців тому

      I found my friend the best in the word and while sharing the best thing with him he stopped talking to me and now😢

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

    Your explanations are always awesome. Just waiting for some full-stack videos from you 😁

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

    Good Video Awesome Explanation

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

    Thank you so much. Been struggling with the App router

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

    Best explanation hands down!

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

      Thank you so much!

    • @dev-akeel
      @dev-akeel 9 місяців тому

      I have no experience explaining anything 😢 so I lost my friend while explaining him something really very important.

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

    very useful and explained in super easy way. Much appreciated!

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

    Hi there! Firstly, thank you so much for the informative video on server actions. I've learned a lot from it!
    I just noticed in the code on page.tsx, there's an unused addExpense function. Since we've already separated the form into its own component and created a dedicated action for server interactions, it seems like this function isn't necessary anymore.
    Perhaps we could consider removing or commenting out this function to avoid confusion and keep our codebase clean. Just a suggestion to streamline things further!
    Thanks again for the awesome tutorial! Looking forward to more content from you. 😊

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

    Really good video!!! Thx

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

    Great explanation. Thank you!

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

    God bless, Brett

  • @HeroKiller-rh6vx
    @HeroKiller-rh6vx 6 місяців тому +1

    Great video thanks man!

  • @SteelCityEndurance
    @SteelCityEndurance 6 місяців тому +2

    Hi, this is pretty straightforward but in the end your writing a function that accesses the database. If you write an API, you can reuse the endpoint as needed. aside from not exposing the POST to the client side how does this benefit the developer ? You're writing the function either way, right?

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

    You don't have to place the cursor on the far right to make a new line, just hold ctrl and enter, you can be anywhere on the line. Same goes for new line above with ctrl+shift+enter. 😊

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

    prisMA!!
    thanks for the video

  • @user-ty3iu3zv3d
    @user-ty3iu3zv3d 7 місяців тому

    Appreciated. 0:14

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

    I wish there was a way to sort of see the cache working in action. Like with react query. Right now we just sort of assume everything works and is safe.

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

      Yea that would be pretty cool but I guess you can test it out by adding new data and make sure you are fetching data by caching and see if the data updates or not

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

    Great vid, thank you!

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

    How can we use server actions client side but outside of form tags, let's say I don't have any input form like calling a server action on click of a add to cart button, and also how to show loading state in that.

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

      I recommend using API routes instead of server functions for that and only way to show loading state is with client side code. You will have to refactor code to suit your case

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

    Hey Brett, awesome Video.
    How do we go about using server actions for calling external APIs where we have to authenticate ourself with headers (using clientid,secret).
    Do we just use fetch or can we use external libraries like axios inside server actions?
    In a lot of explanations we use forms and call our own database using ORMs like prisma, but never external apis.
    Another thing (more directed towards server components) is that it is often very confusing switching from one to another and use them simultaneously, when you can only use states inside client components or async/await inside server components.

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

    Good work

  • @aburaihan-py4vi
    @aburaihan-py4vi 8 місяців тому

    Excellent!!!!!!!!!

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

    Thank you

  • @kenscode
    @kenscode 3 місяці тому

    Great video! I am having trouble finding a resource on how to redirect the user to another page after submitting to the database inside a server action. My code is similar to yours but I have a form with a lot of fields. redirect() says it works but isn't working inside a try/catch block and outside of the block says it's unreachable code 😬

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

    thank you

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

    That will show error "only plain objects can be passed to the client component"

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

    nice video

  • @darioalves7739
    @darioalves7739 3 місяці тому

    When you add the expense, looks like the page is refreshing, right? that's not good.

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

    I haven't found anything about this in the docs, but can you actually access the request object?

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

    Hello, how will realize form validation?

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

    What extension do I need to use for function autocomplete suggestion like you have here? 2:58

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

    What setting or extension do you have enabled to see the vertical ruler on the side, showing opening and closing of divs?

  • @user-im2vm1uz4h
    @user-im2vm1uz4h 8 місяців тому +1

    Thanks for this great tutorial.
    I have a question. Can't we fetch data by using server actions without forms like we do GET request using api route?

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

      Thanks for watching! And I think you can only user server actions on forms for data mutations. If you want to perform a GET request then you should just use a route handler.

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

    why do you call it prism when your clearly writing prismA (love the video learned alot)

  • @crim-son
    @crim-son 9 місяців тому +1

    My main issue with this is that, i can't know if the server action succeeds or fails, what if the user doesn't have a good network?...i have to use a form everytime I want to use server actions, what if i want it on a click of a button?, id rather just stick to creating APIs and making client side requests

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

      I agree with you, I still mainly use API endpoints and only really user server actions on contact forms at the moment. However, things could always change.

    • @crim-son
      @crim-son 8 місяців тому

      I hope Nextjs team sees the struggle with the use of server actions and come up with brighter ideas, its really beautiful not to have to create and API endpoint for every action, but it also comes with consequences@@brettwestwooddeveloper

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

    Thanks for sharing!. I have a question. Why does the title text flash when you add the school supplies? Edit: I found the answer in a github discussion, "I just noticed that the jitter is only there in dev mode. After building the project, it's gone."

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

    is there a link to a github repo :) sometimes this helps to see the whole example at the end?

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

    On the form component, could i just import useState instead of useRef to reset the fields? I’m not that familiar with useRef. Great video by the way

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

      Thank you! And yes you can use useState hook as well to reset the form.

    • @dev-akeel
      @dev-akeel 9 місяців тому +1

      Yes, absolutely useState can be used.
      But it is better to use useRef for better performance, refer to re-rendering in react useState.

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

    Revalidate tag how to use

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

      I talk about how to use the Revalidate tag at 7:26 mark

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

      @@brettwestwooddeveloper revalidate tag not revalidatepath

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

    Maybe it's easier, but you send more code and other things to the client = more code = more traffic + more insecure

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

    Hi, i am self-taught and I've started learning Next.js 13 2-3 months ago, i have learned how to create simple full-stack app, where app communicates to DB via prisma ORM in/api folder's routes. I liked that way, allowed me to separate backend codes from frontend, but now i see Next.js 14 and Server Actions on every corner. What does that mean for me? Should i stop using /api folder way, and start using server actions, or can i still use /api folder way? Thinking of server actions as newer way, as a part of latest version of Next.js, server actions are probably recommended way. It is a big change for me, who did not learn Next.js completely, yet i need to change big part of how i managed db stuff in my app. Thanks to Your video i am starting to understand server actions, thank you. :}

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

      I would still stick with API folder routes. It is better overall in my opinion anyways.

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

    github link please

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

      sorry don't have for this. It's more of a tutorial

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

      @@brettwestwooddeveloper and it would be really helpful if you do tutorial on a large scale project (like may be a million of users ).. like how should we proceed about it. what will be the best practices when we use next 14. how will be the folders structure architecture.. like a boilerplate kinda thing.. I guess nany of us get understanding in small scale app. but get stuck in architecture wise while going for building large-scale application.

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

    i still dont like this idea, just refetch everything, you can have some weird behaviors.. lets say that i have a "big" system where 2 users or more can add the data at the same time, the refetch will bring the new items which i didnt create.
    the optimistic way where you can just push to your state its better

  • @sebas15689
    @sebas15689 29 днів тому +1

    Bro's knoweledge of react : 9.5
    Bro's knoweledge of basic windows: 1
    Lol unless you code in mac or linux I dont understand how is it that you look like my grandma trying to use the computer when moving stuff around the screen

  • @NitinSharma-fh5fl
    @NitinSharma-fh5fl 25 днів тому

    bro you look ai generated

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

    Too much over engineering just to use server actions. I don't think I will be using it. Please viewers don't swallow any new release that comes up, just take a little taste of it and throw it out.

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

      True, I prefer standart front to back communications with API, mutating data

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

      One can really tell you don’t have a clue what you are talking about.

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

      I partially agree with you but yea I think overall I will be sticking with API folder routes.

    • @therealdevopsintern
      @therealdevopsintern 8 місяців тому +2

      @@dawid_dahl your statement tells you don't know what is happening in the developer community. Server actions is fucked when you are using the same API for mobile app development.

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

      @@therealdevopsintern Why don’t you provide some arguments instead of just swearing and acting like an idiot?