Using React 19 with Vite and Next.js

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024
  • Learn about the latest features of React 19, like client and server actions, `useOptimistic`, and more. In this demo, we'll start with a client-only React application using Vite and walk through how React 19 simplifies your application logic and helps create a better UX. Then, we'll move to a server framework like Next.js to show how to use React Server Components, Server Actions, and more.

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

  • @nikilk
    @nikilk Месяц назад +105

    For a moment I thought Vercel, made NextJS work with Vite upon reading the title. At the end I was like oh this is more of a migration from Vite. 😂

    • @relaxwithai
      @relaxwithai Месяц назад +5

      Same here... but was a bit skeptical but then I realized it was a video from vercel. Just decided to watch anyway

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

      Same here.

    • @VercelHQ
      @VercelHQ  Месяц назад +13

      The first half of the video shows using React 19 features with Vite, like actions and `useOptimistic`, and the second half shows some of the features like server actions, server components, and more with a server framework like Next.js.

    • @relaxwithai
      @relaxwithai Месяц назад +10

      @@VercelHQ It think what some people would think especially with the thumbnail is Next.js is adding vite supports which isn't the case.

    • @StephenRayner
      @StephenRayner Месяц назад +2

      Same here, got excited…

  • @LutherDePapier
    @LutherDePapier Месяц назад +8

    I need to keep this video in a tab somewhere available at all times. Thanks.

    • @leerob
      @leerob Месяц назад +1

      Glad I could help!

  • @PhilipAlexanderHassialis
    @PhilipAlexanderHassialis Месяц назад +2

    Great video Lee!
    That being said, this is a good example when your application is a small application and you are early in your dev cycle.
    I would love to see the same exercise (migrating from vite to next) with a big SPA codebase with bighuge redux-toolkit slices, lots of react-router middlewares and loaders and authorizations and whatnot, big react-hook-form forms, the whole shebang and the kitchen sink. Oh, and your API is not in next or JS/TS because of course it's not.

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

      Then u will realise how much u love your legacy code.

  • @rust1477
    @rust1477 Месяц назад +1

    Great video! Can we please get a followup on unit testing (with jest & react-testing-library) forms that use the action prop?

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

    Simple, but great video. Thanks Lee ❤

  • @miervaldis42
    @miervaldis42 Месяц назад +3

    Actually, question : what is the best way programmatically to know if a component is a "server" one or a "client" one ?
    (without relying on the fail import error when you try to import hooks in a server component or if the developer uses "use client", for example, I mean)
    Like is there a way to get Next.js thoughts about a component and then, use it as a boolean to display a message ?
    Maybe it's a weird question but I was curious ^^"

    • @danke1673
      @danke1673 Месяц назад +5

      typeof window === "undefined"

    • @etrepro
      @etrepro Месяц назад +1

      🤣🤣🤣

  • @MattChinander
    @MattChinander Месяц назад +1

    I love the shirt, Lee!

  • @yassinebenazouz4529
    @yassinebenazouz4529 Месяц назад +1

    just add vite support instead of webpack. it is really annoying to wait 10 seconds evrey time i save changes

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

      Why is it taking 10 seconds to see your changes? I use next and I see changes in about 1 second.

  • @r-i-ch
    @r-i-ch Месяц назад +1

    Gre@t video! Are there Examples of Error Handling or Cancelled Requests or Debouncing Requests?

  • @TechHorizonUnveiled
    @TechHorizonUnveiled 29 дней назад

    What VS Code theme does he use?😭

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

    In vite, how did you set up the GET/POST handlers on the server with such minimal code? Can we get a repo?

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

    Let's say if the user has made changes in a current page and action saved that change and redirect to some other page where that data needs to be displayed,
    Will this work?
    save(someData)
    revalidatePath("some other page")
    redirect("some other page")

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

    lol never thought we would be seeing this

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

    I think one of the things that is not spoken about with regards to "just fetching it from a server component", is fetching from an external API that requires authentication. I think it's a common enough use case, probably more common than a Next.js app itself interacting with a database, and yet no one ever makes examples.

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

    more like this please

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

    Its really cool!

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

    When will nextjs 19 be released?

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

    im missing something with the useOptimistic @ 13:40 - how is the `sending` flag getting set back to false? the text conditionally displayed based on that value no?

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

      When the data is fetched it replaces the optimistic update, consequently doesn't include the send property anymore.

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

      @@alexandereble8179 ah right thanks!

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

    I was curious about the "with Vite" part, but seems like we removed it altogether from package.json??

    • @VercelHQ
      @VercelHQ  Месяц назад +2

      The first half of the video shows using React 19 features with Vite, like actions and `useOptimistic`, and the second half shows some of the features like server actions, server components, and more with a server framework like Next.js.

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

      Ah right, it's not possible to use the server-side things with Vite, right?

    • @farzadmf
      @farzadmf 18 дней назад

      @IlllIlIlllIIIllIl Oh wow, thank you; didn't know about that. Are there any links/resources you can share for me to check?

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

    Super awesome!

  • @LutherDePapier
    @LutherDePapier Месяц назад +1

    Basically the db.js file reads, while the actions.js file writes.

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

      And that nothing new, I'm writing CQRS software for decades, but finally liberal kids realised...

  • @HarleyLam-d6j
    @HarleyLam-d6j Месяц назад

    Hey, how Next.JS stuffs live without SQL or database features?

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

      API ?

    • @HarleyLam-d6j
      @HarleyLam-d6j Месяц назад

      @@ben53933 Neat, we have back end teams for those purposes

  • @mauricenoever
    @mauricenoever Месяц назад +1

    Nice video.
    I have two questions
    1. Can I use the optimistic hook without a form and Form action ?
    I use a simple textarea and on Click it will send a post request over axios to my laravel Backend.
    2.When will Turbopack production be ready for next JS production builds ?

    • @r-i-ch
      @r-i-ch Месяц назад

      A textarea is a form component

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

    useOptimistic should be clearing the input fields by default.

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

    Sorry for asking this, but what theme are you using for VSCODE?

    • @leerob
      @leerob Месяц назад +1

      One Dark Pro Darker

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

      @@leerob thank you very much! 😊🙏

  • @olicodes
    @olicodes Месяц назад +2

    When will React 19 be released?

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

      Hopefully pretty soon! Have you been using the RC?

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

      When the React team figure out how to handle fallbacks with multiple branches more gracefully!

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

    remix baked into react19 with just a bunch of made up hooks, nice. waiting for rr7

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

    итого просто переделал под nextjs

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

    He's cooking

    • @leerob
      @leerob Месяц назад +1

      let him cook

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

    👍🏻

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

    чтоооо

  • @rayorole3065
    @rayorole3065 Месяц назад +1

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

    At least wait for release lil bro