A guide to using Next 14 (server actions, RSC, useFormState, useFormStatus)

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024
  • link to code: github.com/web...
    📘 T3 Stack Tutorial: 1017897100294....
    🤖 SaaS I'm Building: www.icongenera...
    ▶️ Generate Chapters: ytchaptersgene...
    💬 Discord: / discord
    🔔 Newsletter: newsletter.web...
    📁 GitHub: github.com/web...
    📺 Twitch: / webdevcody
    🤖 Website: webdevcody.com
    🐦 Twitter: / webdevcody

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

  • @pablus-r1h
    @pablus-r1h 10 месяцев назад +6

    Cody, your teaching style is truly exceptional and best of all: no unnecessary fluff. I just immersed myself in a series of your videos and gained so much valuable knowledge.
    Thank you very much, and thanks YT for putting your channel on my feed! 👍

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

      Thank you! Glad you like it

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

    This is great, I always get overwhelmed when there is too many features being added to something I use, love seeing these videos just running over the changes

  • @codinginflow
    @codinginflow 10 месяцев назад +4

    You can also skip noStore if you revalidate the path from your server action. That's incremental static regeneration.

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

    Thanks man, you're always on time i really needed that ! plus your explanation is easy !

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

    Saw you repost this video on Twitter, glad I bookmarked it and came back to watch it. Great stuff!

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

    Fantastic video thank you! I think I'm gonna make the switch from tRPC to server actions finally

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

    For checkboxes you could probably still use input with a button then make this button to be transparent and position it on top of a checkbox

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

    Thanks man! I think todo app is perfect if the focus is learning these kind of features.

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

    Just searching for drizzle and your vids showing up - uploaded 2 min ago 😂

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

    I finally understand server actions now lol thanks dude

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

    Excellent Video! Keep up the good work!

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

    Cody youre the🐐This video was super helpful!

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

    Excellent! How about using a server action to do a search based on criteria of a form, and display the returned data back to the screen? Everyone on youtube shows examples like yours (inserts or deletes) and then they display ALL the data. But I would like to see an action to do simple query (using conditions from the form).
    In this case I am not sure what to do. The component containing the form will still be a server component like in this example? The results, if they are displayed in a separate component, a results component, then that results component will also be a server component? (I guess that in this case the app will look like a php app, totally) or a client component? Am I thinking to the right direction or the approach should be different? Should I return to the fetch/API/useState approach?
    Thanks man...

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

      One approach is to put your search string in the query string, and redirect when someone runs a search, then your RSC will rerun and refetch the subset of data and display it

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

    Hey Cody, I built an app that was on the page router last year, a nice s ide project that makes abit of money with the OG page router t3 stack. Im now working on my 2nd side project, and might learn app router and drizzle orm (instead of prisma) can I ask why tRPC can still be an option even in the app router on T3? Is it only used for client side calls or is it both? Really confused but would love to know.

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

      it's still a great option, but I personally switched to server actions instead of tRPC

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

    Hi please i need help with this
    I'm fetching data from a server component and passing it down as props to a client component but I'm getting this error "Error: Maximum call stack size exceeded" when i use the .populate on my Model.....Please what are the possible reasons for this problem?

  • @zhenobiikuzo4957
    @zhenobiikuzo4957 Месяц назад

    hii, may I ask why we still need react hook form in server actions?

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

    Super interesting thanks a lot !

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

    Instead of encapsulating the create form into its own component, you could’ve just gave it a key unique, couldn’t you? Maybe based on the length of the todos or some fingerprinting of the set

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

    Love you! Great job! First 👸🏿

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

      🙌🙌🙌🙌🙌 thanks babe!

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

    Can you please resume the react interview series, they were really fun to watch

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

      I just published one today

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

      @@WebDevCody yes please it very inresting and we learn a lot even help to crack interview thanks

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

    If you wanted to use the same server action on different pages how would you revalidate path on each different page?

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

      I wouldn't reuse server actions on other pages personally, but I guess you could pass the path as an argument and the action could just dynamically revalidate based on the passed path

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

    Noticed that drizzle has an icon in your vscode icons, what icon extension are you using?

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

    Would people still recommend using tRPC with Next14? Loving the videos Cody!

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

      I think they both kind of solve the same issue which is "end to end" typesafety. I have personally been leaning on server actions since they achieve it.

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

      ​@@WebDevCodyhow is next.js 14 comparably type safe when you're casting the request parameters? (5:42).

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

      @@flexdashwell, in this video I'm doing progressive enhancement to allow the app to work without javascript enabled; this requires using FormData which isn't typed. If you just invoke the server actions directly from onClick callbacks, the arguments and return values are all typed. tRPC won't work with progressive enhancement from what I understand either

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

    When submitting a form on a client component with useFormState hook, the app undergoes a hard reload, resulting in the loss of all cached data.
    Edit: I have a client component (a form) that is using useFormState hook, if fetch goes well i call revalidatePath and redirect outside of try/catch. The problem is redirect because if I remove it then it wont do a hard reload.
    How can we prevent this from happening?

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

      What cached data are you losing?

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

      @@WebDevCody I have a tickets page where data is initially cached upon the page's first load. However, when I navigate to the create ticket page and submit the form using , I'm redirected back to the tickets page, triggering a hard reload. This hard reload results in the loss of cached data across all pages.
      The documentation suggests that using a redirect in a server action is acceptable, but in practice, it isn't. To address this, I modified the create ticket form to and, within the onSubmit function, triggered an action. Upon successful completion, I utilized router.push(...)-and with this adjustment, the process now works seamlessly.

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

    Could you do a follow video to this especially the useFormState and unit testing the component that uses it?

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

    For someone building a new production app, would you recommend prisma or drizzle now that you have played around with them both? Would love your input on this

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

      so far I'm liking drizzle a bit better, but they are both great IMO. drizzle is a bit lower level and requires more knowledge of how SQL works I'd say

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

      Thank you, I really appreciate your reply @@WebDevCody ❤

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

    what about "drizzle-kit generate"? it seems you skipped this step

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

    Followed along integrating with my own code, then got frustrated and used your repo code directly but the form is not clearing with defaultValue={formState.text} yet the error reporting on the same return works well. running Next 14.1.1-canary.58

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

      Sorry too hard to help debug over yt commenfs

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

      @@WebDevCody Would not think that is possible but would like to know if you have any issues with this code on next14 Seems the defaultValue is not updating consistantly but the return value on success is

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

      FYI
      {console.log("text : " + formState.text)}
      Confirms the formState.text is being updated on chrome console (tried "" and "*") but its not updating the input? @@WebDevCody

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

    formstate and formstatus are expiremental hooks in react, right?

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

    So what if i want to the display a toast after creating a todo?

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

    What are the use cases for people using a browser with disabled javascript?

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

      People on slower machines who don’t want pop ups and modals as they browse. Progressive enhancement is also to help allow interactivity when the JavaScript hasn’t loaded yet. For example, clicking on a button before react initializes will cause the button to do nothing.

  • @mehmethanifierenler3612
    @mehmethanifierenler3612 Месяц назад

    thanks

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

    6:19 - is something similar happening when using Prisma? And how could I resolve it, when using Prisma instead of Drizzle? I would be so thankful.
    Edit: Same code for those working with Prisma:
    import { PrismaClient } from "@prisma/client";
    import { env } from "~/env.mjs"; // or use node's process.env instead
    const globalForPrisma = globalThis as unknown as {
    prisma: PrismaClient | undefined;
    };
    export const db =
    globalForPrisma.prisma ??
    new PrismaClient({
    log:
    env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
    });
    if (env.NODE_ENV !== "production") globalForPrisma.prisma = db;

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

      yes, I do think you need similar code for Prisma to prevent too many connections

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

      @@WebDevCody Found in T3 stack an example, I didn't know about it until now, that it's needed. Many thanks!!

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

    This is pretty much like Remix with extra steps

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

    Great

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

    can you share the code with us please?

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

      yes sorry: github.com/webdevcody/todo-drizzle

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

    Com on man. This is so no makes sense staff. Soo many abstractions that is not really fun to write. Code makes no sense to read and write. I want to clearly see the boundary between client and server, where my traffic falls out and comes in. Pretty useful nextjs for the frontend and RSC is great for dynamic and static generation. I prefer having separate http api server over. Had no chance to use server actions. After watching the video had no excitement for trying it, the video is the great though, clear explanations.

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

      I really enjoy server actions personally. Much better DX than hitting api endpoints directly

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

    Please provide time stamps for a 31 minute video

  • @thespiritualjourney369
    @thespiritualjourney369 10 месяцев назад +6

    If it's a beginner's guide, then why are you using Drizzle and Docker n all? Some of us, including me, don't know all that stuff. You should only teach NextJS 14 and the rest of the stuff that you have included in the title, which I know you will do in the video. but I am saying this should only be a next-step guide.

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

      Good point

    • @lisander-lopez
      @lisander-lopez 10 месяцев назад +6

      Disagree. Docker has nothing to do with nextjs itself... its just a way to "run" your application.. you can run any other framework on docker...... same with drizzle. His video was veryyy good for nextjs 14. I would ARGUE that him introducing those other "technologies" would help the beginner question it and do some more research and self learning (the whole point of development! Its always evolving)

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

      what? Truly skill issue. Come back once you’ve learnt. Don’t expect to be spoon fed

    • @lisander-lopez
      @lisander-lopez 10 месяцев назад

      @@real23lions I never said I want to be spoon fed? I specifically said "self learning"

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

      @@lisander-lopez oops i meant to reply to OP, not you. my bad. i just edited it

  • @klevert7287
    @klevert7287 Месяц назад

    actions.ts is that right? or tsx is just fine

    • @WebDevCody
      @WebDevCody  Месяц назад

      It’s possible to return a jsx component from a server action, so tsx if needed