Server Actions in Next.js (useFormStatus, useFormState, Error Handling)

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

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

  • @Kulkarniankita
    @Kulkarniankita  9 месяцев назад +3

    hey friends, what would you like to learn next? Comment below and let me know! Plus press like if you enjoyed this type of content!

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

    Thanks for the video!! it was really helpful and straight forward!! i was studying next13 and my troughts were to change all actions to fetchs so i could give it a key to invalidate when new data is submited.. didnt know that it was possible to revalidate the path entirely. Thanks

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

      Amazing, glad it was helpful Edson! And yes our thought process should change entirely

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

    Great video! One thing I found really useful but haven't seen documented by Next at all is that server actions, provided they are stored in a separate file with 'use server' at the top, can be imported anywhere on the client and called to return a promise.
    The promise will resolve to the return value of the server function. This has allowed me to refactor a ton of client-side api calls to server actions, even though they were being made in async code, in non-component files.

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

      Thanks Trad! And ohh this is a very interesting way. Thanks for sharing. Do you think you can share any code sandbox example just to make sure I fully understand?

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

      @@Kulkarniankita RUclips keeps removing the link to my code sandbox. It lives at "distracted-meitner-c2gpp5", after the traditional url.
      Out of the the box, it should show you an alert containing server data as a proof-of-concept. The alert is triggered from inside a useEffect() call that calls a function outside of a component file, which calls the server action.
      My use case for this is that my app uses redux-saga for managing side-effects, so there's a lot of async code outside components which can be triggered by redux actions. Now all the graphql code for my api wrapper can live on the server.

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

    Thank for tutorial,easy to learn

  • @ralstonalmeida8034
    @ralstonalmeida8034 9 месяцев назад +2

    Great video, I finally understand server actions now!

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

    This concept is excellent for creating a monolith project simultaneously similar to PHP. The API will always be present for projects where the interface is available to other resources within the project ecosystem, simply put, when an endpoint is called from various other platforms that communicate with consistent data in the database. My question is whether even if the API call must stat to use server action or use for example React Query or other superstructures to call API endpoint?

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

    Thank you for the video, I hope you make lots more . your explanations are clear and concise.

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

      Thanks Saabir, I plan to create more! :)

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

    great video

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

    I am the first to watch 😂
    I love your teaching style!

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

      Thank you for being the first one to watch it, and awesome! 🙌

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

      @@Kulkarniankita tell me, I planning to subscribe to your course nextjs through ZTM,which is part of the React developer career path,do you advise me to to take that course path instead of Full stack developer path which more developers don't advise to beginners like me? I love React/nextjs,please advise..thank you

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

      I would go for the react dev career path first and then jump onto the full stack one once you are a bit more comfortable with the Frontend. The reason being that you will know how to Differentiate between backend and Frontend errors plus will know Frontend already!

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

      @@Kulkarniankita
      Thank you so much,highly appreciated!

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

      @@Dr_PhilK of course, anytime! Happy to answer any questions you may have :)

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

    that was an excellent representation of GET and POST, what about PUT and DELETE?

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

      Thanks, glad you liked it! I didn’t as the video was getting really long but it should give you an idea now for how to do the same :)

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

    Friend, could you make a video in which cases we can use client components and server components? for example in an Ecommerce. thanks video
    suscribed

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

      Thank you friend! this is a great idea - will do this :)

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

    Hi Ankita, here in nextjs I am using only frontend part and backend I python ,so the server actions only handle at the backend of nextjs ,not yet from the frontend is it correct what I think and I am using pages folder only not app folder in nextjs13.5.6v

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

      You need to use the app router and not pages to use server actions. To use server actions, you would need to have your code in JavaScript; otherwise I can't imagine how the actions will be called. And I'm not sure what you mean by “server actions not yet from the front-end.”. You declare an action and call from your form in the front-end.

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

      @@Kulkarniankita for protected routes which is the best method to go in nextjs from only front end part and no need from the backend part

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

    as nextjs is evolving very fast...should we totally move from react to next?

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

      Next uses react so you can’t move away from react. You need to learn both in parallel but Next is now one of the most popular ways to create Frontend apps!

  • @ZainRamzan-pt8cm
    @ZainRamzan-pt8cm 5 месяцев назад

    Hey ankita , I am curious that to know how i can validate the data on client side before sending it to the server.
    In my project i am using the nextsafeaction with zod and for text update it is working fine but i am unable to find a solution how to upload file with nextsafeaction and next server actions

    • @Kulkarniankita
      @Kulkarniankita  5 месяцев назад

      I haven’t used that library so I would lean on zod to validate data like I have shown in the course!

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

    Hi Ankita,how to set the initial page to be login like localhost:3000/login to be the first actually in pages folder we can set in the index.tsx but in the app router how to do

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

      You could try use middleware as I’m guessing you want to check credentials and accordingly route them to login or dashboard/main page.
      nextjs.org/docs/app/building-your-application/routing/middleware

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

      @@Kulkarniankita /** @type {import('next').NextConfig} */
      const nextConfig = {
      async redirects() {
      return [
      {
      source: "/",
      destination: "/login",
      permanent: true,
      },
      ];
      },
      };
      module.exports = nextConfig; so can we use like this is it correct way

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

      @@sai7743 yes that’s another way but if you need to check credentials beforehand to route them to login or dashboard then you might need middleware for that but if not, this works too!

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

      @@Kulkarniankita so here my way what I am doing initially to land the login page so that time login page available in that username and password available and submit into the dashboard. And middleware we can use for the protected route and based on the token cookie if token available then into the dashboard or else it will remain into the login page

  • @im.webdev
    @im.webdev 9 месяцев назад

    how to store image on database and webhost

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

      You can check this article for your question.
      stackoverflow.com/questions/54500/storing-images-in-postgresql?rq=4

  • @tarunmehrda
    @tarunmehrda 9 месяцев назад +2

    upload daily video

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

      Lol I wish, it’s a lot of work to create quality content and upload a video which takes time so going to stick to weekly!

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

    Your website frontend.. is not working.

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

      Which website?

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

      @@Kulkarniankita I wanted to subscribe to your newsletter. Ten minutes ago, I attempted to open the link, but it wasn't working. However, upon trying again just now, it worked. Thank you for your response.

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

      Hey! Which website are you talking about? Kulkarniankita.com or frontendsnacks.dev? Thanks for letting me know, I’ll try it!

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

    modern php

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

      100% I agree, funny we are going back to the patterns that worked!