How To Use Next.js 14 Server Actions

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

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

  • @3J2A3Y
    @3J2A3Y 9 месяцев назад +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.

  • @TypeScriptTV
    @TypeScriptTV 27 дней назад +1

    Very nice and concise tutorial! I learned a lot from it. 👍

  • @creciendotech
    @creciendotech 5 месяцев назад +2

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

  • @belgi76
    @belgi76 10 месяцев назад +3

    Perfect explanation about the server actions.

  • @enz1222
    @enz1222 8 месяцев назад +1

    Never seen a better explanation than this 💯

  • @fahdfady6632
    @fahdfady6632 8 месяцев назад +2

    Amazing, it all makes sense now.

  • @TribhuwanKushwaha-e7y
    @TribhuwanKushwaha-e7y 7 месяцев назад +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.

  • @prashlovessamosa
    @prashlovessamosa 10 месяцев назад +2

    Thanks for sharing Brett.

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  10 месяцев назад

      You are welcome!

    • @dev-akeel
      @dev-akeel 10 месяцев назад

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

  • @satvik0099
    @satvik0099 10 месяцев назад +1

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

  • @jpisty
    @jpisty 7 месяцев назад +1

    Thank you so much. Been struggling with the App router

  • @merakli2022
    @merakli2022 10 месяцев назад +2

    Well done. Keep up the good work!

  • @ekchills6948
    @ekchills6948 10 месяцев назад +3

    You always know what we need

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  10 месяцев назад +1

      Glad I could read your mind

    • @dev-akeel
      @dev-akeel 10 месяцев назад

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

  • @NOTHING-en2ue
    @NOTHING-en2ue 10 месяцев назад +1

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

  • @lukyno5751
    @lukyno5751 7 месяцев назад +1

    Really good video!!! Thx

  • @SriramPrasanth-n9c
    @SriramPrasanth-n9c 5 месяцев назад +1

    Good Video Awesome Explanation

  • @whezboo
    @whezboo 6 месяцев назад +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. 😊

  • @meilyn22
    @meilyn22 10 месяцев назад +1

    Best explanation hands down!

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  10 месяцев назад

      Thank you so much!

    • @dev-akeel
      @dev-akeel 10 месяцев назад

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

  • @dawid_dahl
    @dawid_dahl 9 месяцев назад +1

    Great explanation. Thank you!

  • @muneeburrehman547
    @muneeburrehman547 6 месяцев назад

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

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

    Wow. You explained it all. Thx

  • @SteelCityEndurance
    @SteelCityEndurance 7 месяцев назад +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?

  • @hr94op
    @hr94op 27 дней назад +1

    Man, thanks!

  • @ayushshende4290
    @ayushshende4290 10 месяцев назад +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  9 месяцев назад

      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

  • @ashimov1970
    @ashimov1970 5 месяцев назад +1

    God bless, Brett

  • @heddshot87
    @heddshot87 9 месяцев назад +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. 😊

  • @HeroKiller-rh6vx
    @HeroKiller-rh6vx 7 месяцев назад +1

    Great video thanks man!

  • @ChrisHaupt
    @ChrisHaupt 8 месяцев назад +1

    prisMA!!
    thanks for the video

  • @blahblahblah-u3m
    @blahblahblah-u3m 7 месяцев назад

    Appreciated. 0:14

  • @sagesofsound298
    @sagesofsound298 7 месяцев назад +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  7 месяцев назад

      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

  • @YuuffyLIVE
    @YuuffyLIVE 6 месяцев назад

    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.

  • @whatdorin
    @whatdorin 8 месяцев назад +1

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

  • @user-im2vm1uz4h
    @user-im2vm1uz4h 9 месяцев назад +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  9 месяцев назад

      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.

  • @BobbyCatesby
    @BobbyCatesby 8 месяцев назад

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

  • @ItsLeonardoGranetto
    @ItsLeonardoGranetto 6 месяцев назад +1

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

  • @rockbotico
    @rockbotico 10 месяцев назад +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."

  • @nicolascondrea8068
    @nicolascondrea8068 9 месяцев назад +1

    Great vid, thank you!

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

    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 😬

  • @techlightdev
    @techlightdev 7 месяцев назад

    Thank you

  • @PeriklesPeriklesoglu
    @PeriklesPeriklesoglu 7 месяцев назад

    thank you

  • @cloudagnostic
    @cloudagnostic 10 месяцев назад +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  10 месяцев назад

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

    • @dev-akeel
      @dev-akeel 10 месяцев назад +1

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

  • @aburaihan-py4vi
    @aburaihan-py4vi 9 месяцев назад

    Excellent!!!!!!!!!

  • @usmanshahid1557
    @usmanshahid1557 10 месяцев назад +1

    Good work

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

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

  • @aguud
    @aguud 9 месяцев назад

    nice video

  • @protonys
    @protonys 6 месяцев назад +1

    Hello, how will realize form validation?

  • @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  9 месяцев назад +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 9 месяцев назад

      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

  • @muradqumizakis8428
    @muradqumizakis8428 9 месяцев назад +1

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

  • @marroos5440
    @marroos5440 10 месяцев назад +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  9 месяцев назад +1

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

  • @Wortkotze1512
    @Wortkotze1512 9 месяцев назад

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

  • @Vickysingh027
    @Vickysingh027 6 месяцев назад

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

  • @hulashmahto99
    @hulashmahto99 9 месяцев назад +1

    Revalidate tag how to use

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  9 месяцев назад

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

    • @hulashmahto99
      @hulashmahto99 9 месяцев назад

      @@brettwestwooddeveloper revalidate tag not revalidatepath

  • @axolotic6981
    @axolotic6981 7 месяцев назад

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

  • @commashalfstrokes7575
    @commashalfstrokes7575 9 месяцев назад +1

    github link please

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  9 месяцев назад +1

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

    • @commashalfstrokes7575
      @commashalfstrokes7575 9 месяцев назад

      @@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 8 месяцев назад

    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 Месяц назад +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 Месяц назад

    bro you look ai generated

  • @therealdevopsintern
    @therealdevopsintern 10 месяцев назад +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 10 месяцев назад

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

    • @dawid_dahl
      @dawid_dahl 9 месяцев назад

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

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  9 месяцев назад

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

    • @therealdevopsintern
      @therealdevopsintern 9 месяцев назад +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 9 месяцев назад

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