Ryan Toronto
Ryan Toronto
  • Видео 26
  • Просмотров 226 181
React 19: useActionState
In this video, we'll build a form using React's new useActionState hook, introduced in React 19. Along the way, we'll explore other exciting features from React 19, including form actions, server functions, and server components. Learn how these tools make building forms easier than ever!
One thing I forgot to mention: useActionState can only be used inside client components. That's why we have a separate registration form component - it's a client component, but I forgot to show/explain that in the video.
Black Friday Sale: buildui.com
- 0:00 - Intro
- 0:25 - Actions and server functions
- 5:09 - Returning data to the browser
- 7:21 - Use action state
- 12:21 - Adding feedback to the form
- 14:5...
Просмотров: 1 193

Видео

Handling RSC Errors in Next.js
Просмотров 3 тыс.9 месяцев назад
In today's video we'll use an error boundary to refresh a React Server Component that threw an error. We'll also dive into transitions and see how they allow us to batch together state updates that finish at different times. - 0:00 - Intro - 1:06 - Error handling in Next.js - 2:11 - Resetting without fixing the error - 3:16 - Rerunning the server component - 4:23 - Avoiding race conditions with...
Where should this component run?
Просмотров 1,8 тыс.9 месяцев назад
I love how the RSC architecture approaches bundling and running React components. Non-interactive components run on the server, keeping the initial load fast and the bundle size small. Meanwhile, interactive components are run on the client, making the UI feel snappy and instantaneous. But what about components that need to run on both the server and client? How does the RSC architecture addres...
Asset loading in React
Просмотров 2 тыс.10 месяцев назад
In this video we’re going to take a look at the new Asset Loading feature coming to React 19. - 0:00 - Intro - 0:40 - Flash of unstyled content - 1:46 - Asset loading in React - 4:13 - Books app - 6:40 - The bookshelf component - 7:18 - How the transition works - 9:12 - Stylesheets do not unload Source code for books app: github.com/ryanto/asset-loading-suspense Check out my website: buildui.com
Out-of-order streaming in React
Просмотров 7 тыс.11 месяцев назад
Wish your users could see content instantly, even if data takes a second? In this video we're going to learn how out-of-order streaming allows React Server Components to render independently, showing your UI as soon as possible! - 0:00 - Intro - 0:15 - Introduction to streaming - 2:14 - Out-of-order streaming - 4:29 - Streaming and Suspense - 8:04 - Streaming multiple components - 9:41 - UI ide...
Preloading data (React's cache part 2)
Просмотров 1,7 тыс.11 месяцев назад
In this video we're going to continue where we left off in part 1 and use React's cache function to preload data. Watch part 1 here: ruclips.net/video/MxjCLqdk4G4/видео.html - 0:00 - Intro - 0:23 - Fetching data for the page - 4:15 - Why is the page slow? - 6:35 - Using cache to avoid waterfalls - 8:47 - Is preloading unused data okay? My website: buildui.com
React's new cache function
Просмотров 11 тыс.11 месяцев назад
In this video we're going to look at how React's cache function helps avoid unnecessary data requests. - 0:00 - Intro - 0:34 - Loading the current user - 2:31 - Using React’s cache function - 4:06 - Why not use props? - 7:51 - Good things to know about cache Preloading data with cache: ruclips.net/video/_gZ3ctkbGPo/видео.html Check out my course "Data fetching with React Server Components" here...
Why you can't set cookies in Server Components
Просмотров 12 тыс.11 месяцев назад
Today we're going look at why you can't set cookies when rendering server components in Next.js. - 0:00 - Intro - 1:22 - Setting cookies in RSC - 2:43 - Suspense - 5:13 - Streaming - 6:55 - Anatomy of an HTTP request - 9:22 - Setting cookies in Next.js For more videos on React check out buildui.com/
The useTransition hook
Просмотров 1,6 тыс.Год назад
Hi everyone! I wanted to share a free lesson on the useTransition hook from my course "Data fetching with React Server Components". - 0:00 - Intro - 0:23 - Start of lesson - 0:46 - useTransition hook - 2:22 - Styling the searching UI - 3:24 - Lesson outro - 3:56 - Outro Join Build UI: buildui.com/pricing Course: buildui.com/courses/react-server-components
Refresh React Server Components
Просмотров 5 тыс.Год назад
In this video I'm going to show you how to automatically refresh a Next.js app whenever data in an external system changes. Code: buildui.com/recipes/refresh-app-router-cache-server-action - 0:00 - Intro - 1:23 - Server action - 4:18 - Refresh component - 6:49 - Interval with focus event - 9:47 - Outro Check out my latest course "Data fetching with React Server Components" exclusively on Build ...
Why I use Zod with Server Actions
Просмотров 14 тыс.Год назад
In this video we're going to take a look at how Zod makes FormData easy to work with! Check out my Build UI course on React Server Components: buildui.com/courses/react-server-components - 0:00 - Intro - 0:23 - Introduction to Server Actions - 2:58 - Problems with FormData and TypeScript - 6:14 - Introduction to Zod - 10:17 - Dealing with Checkboxes - 12:35 - Code cleanup - 13:42 - Summary - 14...
Query params with TypeScript
Просмотров 3,2 тыс.Год назад
In this video we're going to use TypeScript to recreate the type for query parameters.
Next.js Deploy Notifications
Просмотров 7 тыс.2 года назад
In this video we're going to build a simple version of the next-deploy-notifications library from scratch. Next deploy notifications: github.com/ryanto/next-deploy-notifications
Transitions that Suspend - React 18
Просмотров 3,1 тыс.2 года назад
Today we're going to take a look at the useTransition hook that's new in React 18. Source code: github.com/ryanto/suspense-transitions
Refactoring from useState to useReducer
Просмотров 9042 года назад
Today we're going to refactor a database app from useState to useReducer. Source: github.com/ryanto/use-state-vs-use-reducer
Testing images with Cypress
Просмотров 11 тыс.2 года назад
Testing images with Cypress
Next.js Modal Routing
Просмотров 35 тыс.3 года назад
Next.js Modal Routing
Reacting to time - useClock hook
Просмотров 6233 года назад
Reacting to time - useClock hook
Synchronizing intervals in React
Просмотров 4413 года назад
Synchronizing intervals in React
Popup Menus in React with Popper.js
Просмотров 22 тыс.3 года назад
Popup Menus in React with Popper.js
Customizing Complex React Components
Просмотров 3,2 тыс.4 года назад
Customizing Complex React Components
Customizing Amplify's Login
Просмотров 17 тыс.4 года назад
Customizing Amplify's Login
Amplify login + React
Просмотров 1,9 тыс.4 года назад
Amplify login React
Debouncing with React Hooks
Просмотров 9 тыс.4 года назад
Debouncing with React Hooks
Why does React need keys - Part 1
Просмотров 5714 года назад
Why does React need keys - Part 1
Click Outside to Close - React Hook
Просмотров 52 тыс.4 года назад
Click Outside to Close - React Hook

Комментарии

  • @RapPayne
    @RapPayne День назад

    Does this presuppose a NextJS project? Like, you need Server Actions to use useActionState and Server Actions only work with NextJS (or maybe Tanstack), right?

    • @RyanToronto
      @RyanToronto 19 часов назад

      Great question! In my video I used a server function, but useActionState can work with anything that's async. Server Actions, Server Functions, and even regular old fetch will work. As long as it's async useActionState will wait for it to finish before the next submit runs.

  • @tofazzalhaque3613
    @tofazzalhaque3613 8 дней назад

    Great video! I struggled with this issue for a while and couldn’t figure out why it wasn’t working. Could you suggest a way to store the access token and refresh token in a server component? Specifically, while the server component is rendering, the access token might expire and need to be refreshed and stored again after obtaining a new one. Currently, I’ve used ioredis, but it’s not supported in middleware, and I don’t think it’s ideal for this use case. Is there a better solution that works with the Edge Runtime and allows setting cookies directly from the server component? Thanks again, Ryan!

    • @RyanToronto
      @RyanToronto 8 дней назад

      Glad to hear the video helped! That's a tough one and I think it can be hard to solve. I've run into a whole bunch of node libraries that won't run on edge runtime as well. Usually what I do is setup a node server and then have my edge runtime code make fetch requests to that node app. Then the node app can talk to redis using ioredis. It adds an extra hop, but if the node app and next app are running close to each other you can minimize latency. I know it's not a great approach, but it's hard to find good solutions with edge runtime. Another option would be to find a redis server that can work with `fetch`, since fetch is the way to do IO in middleware today. Sorry to hear you're having trouble with middleware. I'd be very curious to know what kind of solution you come up with. I don't know how to solve these types of problems well.

    • @tofazzalhaque3613
      @tofazzalhaque3613 7 дней назад

      ​ @RyanToronto The concern is that we can't update cookie in the server component, so we can't store the tokens in cookie. At this moment, Redis comes into the picture, and Redis can be managed by using 'API and fetch' from middleware. Still, it doesn't feel like a good or optimal solution. I hope you will research more and come up with a good solution.😊

  • @espritcritik
    @espritcritik 17 дней назад

    Thank you 👌

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

    Honestly idk why this channel hasn't blown up yet. The way you teach is just remarkable, it's not just about how to implement the feature but how it works under the hood. At least for me, that's the way i really grasp on things, by understanding how they're working under the hood, even if it's a high level explanaition, we have the docs to grind on the nitty gritty details in case we need to (in specific use-cases) anyway. Btw, also the useOptimistic hook it's so misunderstood, i've only seen Sam Selikoff use it the right way in one of his talks. The rest of the RUclipsrs or Tech Influencers don't really get it they just make content lol would be great if you ever talk and deep dive about useOptimistic :) Content of quality like this is much needed and appreciated! Thank you, and Sam.

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

      Thanks for the kind words! useOptimistic is a great idea for a video

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

    Great explanation ++++++++++ 🙂

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

    All good ! but I have one doubt if I need to set the cookie not after the app initialisation(middleware) but rather after a function(server action) works, for example user authentication setting tokens , traditionally the cookies has to be set after the storage of user details in the database, So uh how to implement this particular method, any solutions

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

      Great question! You can totally set a cookie in a server action! Once you write data to the database call cookies().set right inside the action. It should just work :)

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

      @RyanToronto will try it out

  • @JerryHu-i5r
    @JerryHu-i5r Месяц назад

    Why can't you send cookies on the initial page serve? Since you are sure that no additional streaming is happening for the initial HTML?

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

      That's a great question. You technically could, but if your code ever got moved inside of a Suspense boundary then it would all of a sudden stop working. So Next takes a hard line about setting cookies during render.

    • @JerryHu-i5r
      @JerryHu-i5r Месяц назад

      @@RyanToronto Thanks for the reply, yeah I am not a big fan of setting the cookies on the middleware only since it runs on every route. In this case I have token refreshing logic when entering some private routes implemented, so it would be nice to do this on the initial page render. Currently have no choice but to place it on the middleware.

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

    thanks

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

    Awsome

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

    Thank you for this video❤

  • @real-oppenheimer
    @real-oppenheimer Месяц назад

    Your teaching style clicks so much for me, even though these are more complicated topics. It is calm, organized (with a clear, step-by-step path) and you're answering questions while they pop in my head. Thank you!

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

      Wow, thank you! Appreciate the kind words

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

    HI Ryan awesome video makes sense thanks for taking the time to create this. Would love to see the extra video to add the photo 🙂 could you possibly include how you can integrate RHF to this?

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

      Thank you! I'm not a RHF expert, but that's a great question. I think by the time React 19 gets released they will have an answer for React 19+RHF.

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

      @@RyanToronto hey no worries, hopefully something will come out for it. In any case keep up the great work always a pleasure to watch these videos!

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

    Thank you! We need more videos Ryan!

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

    Please not only do the photo example but talk more about transitions. Like I said before, you and Sam are the best, thankfully I bought lifetime subscription to buildui.

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

      Thank you and thanks for joining Build UI, we really appreciate it! More on transitions is a great idea, I'll see if I can find some good examples to make videos on that.

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

    I've always been interested with Transitions. The sad part is, react official docs have docs on useTransition etc. but not one page defines what are transitions and what all APIs support them.

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

      Ya, totally. I think once 19 gets released we'll see more people sharing blog posts and code examples around transitions. Fwiw, I found the usage section of the docs to be helpful: 19.react.dev/reference/react/useTransition#usage, but I think I'm the type of person that learns best by playing with things, so the usage examples might not be for everyone.

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

    thank you Ryan, and yes we want more :)

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

    Hi, how can i revalidate a react cache function

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

      Hey there! This cache is very short lived, it only lasts for the life cycle of the request so there's no invalidation.

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

    The best 🔥. Need more

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

    36 minute video, would love to see more long form content from you

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

    Awesome insight. This just saved me a huge stress of tinkering around.

  • @PrasadKumkar-t3z
    @PrasadKumkar-t3z 2 месяца назад

    Thank you

  • @AnasSiddiqui-n2y
    @AnasSiddiqui-n2y 3 месяца назад

    Great 🔥

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

    Ryan please help me i am submitting a form with server action i am setting cookies from middleware.ts they were setting correctly but i don't know why my client components get resets with default value and when submit my form again it works normally

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

    This video helped me a ton

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

    Very nice video, works, but i have a different problem i am facing, i have a dashboard, data are updated every 5 minute by a backend microservice, when this background process on the server finishes, it does call revalidate using webhook on the nextjs app. my problem is I am calling router.refresh() (lets say every minute), the pages does not refresh, its still using stale version,, and I am hopeless, i tried so many approches, obviusly, your works, but it triggers re-render server componnets by every user connected. thanks

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

      Hey sorry for the late rely. Are using revalidatePath in the webhook? I'd start there. The next caching is really tricky and hard to get right, especially for big apps.

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

      @@RyanToronto yes, I was, but i found a problem, my app was deployed on GCP and the default setting is to CACHE 1h .... so thats why it was all wiered.

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

      @@PeterJanickovic Ah that's good to know! Glad you got it fixed

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

    Thank you Ryan, I really appreciate the calm and clear manner with which you teach! I am newer to Zod and I decided instead of fumbling with the API, I'd find some videos to help me understand it from first principles. This definitely helped!

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

    Damn. Thanks for this video. I have been trying to wrap my head around almost the exact same problem for days now. This pattern opens up a lot of new opportunities. I am actually pumped now 😀 Didn't see your channel before, but just left a sub. This one was dope. Thanks man, keep it up 👌

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

    FYI you don't even need javascript, you can use webcomponents/slots to achieve the same thing. No client side JS needed.

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

      Nice. The slot element looks very cool

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

    Very interesting. It is done through long lived http connection or websockets behind the scenes?

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

      It's a single http connection. In fact, it's the same connection that renders the first html you see... so I guess its a bit like long polling. As soon as all suspense boundaries are resolved the connection closes.

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

    Very good video thank you!

  • @athar-q
    @athar-q 4 месяца назад

    But middleware is invoked for everyone request made from browser. Do we want to cookie-setting-logic to run on every request?

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

      Check out the matching paths section of the Next.js docs to control which paths middleware should run on: nextjs.org/docs/app/building-your-application/routing/middleware#matching-paths

  • @AJPHIL-Dev
    @AJPHIL-Dev 4 месяца назад

    Gonna see if this can work for videos

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

    That is such an awful reason why I cannot set cookies in the page server component. Why can I not set it before calling any Suspense? This solves the issue. And only if you using Suspense then I cannot set any cookies

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

      I believe the reasoning is that if you ever refactor your page into one that uses suspense all the cookie code would then break. Middleware is a recommended way to do it from Next.js.

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

    A very great video. One issue I have faced and wish to understand, what about setting the expiry time for that cookie, lets say a userToke, which is essential so when it expires it can be cleared. Hope the question makes sense. Hoping to hear from you soon

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

      Great question! You can use the `maxAge` or `expires` option from Next's cookies().set function. See more details here: nextjs.org/docs/app/api-reference/functions/cookies#options

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

    How to get cookies from browser in server component/server actions so we can send the cookies with request to backend API request. Please 🙏 reply I'm not able to find any solution

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

      cookies().get('name') should allow your server component to get cookies from the incoming browser request.

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

    Really nice, didn't know that and really useful.

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

      Thanks you! Glad you enjoyed it

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

    This was very enlightening. Another place to set cookies is in route handlers!

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

    You can use my RSC philosophy whenever you have mutable data to handle you should have client components otherwise for immutable data you should use server components

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

      interesting way to summarize it! thanks!

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

    What to do in a case when the user clicks on a route "/throws-sometimes" that's included in navbar? Can the error be reset via clicking on a link to the route within navbar? e.g. <Link href="/throws-sometimes">Throws sometimes</Link>

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

      I haven't tried it, but I wonder if it just works? If not, my first thought was you'd have to somehow get the reset into the nav bar so the error could be dismissed. Let me know what you come up with, I'd be very interested to know how you went about solving this type of problem.

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

      @@RyanToronto Yeah, it's not working. I gonna try, if I'll make it I'll let you know :) Thanks

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

    Can it work with aaync functions

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

      In the upcoming React 19 release there will be support for transitions to take an async function. Right now they are calling these "async transitions". Hope that answers your question!

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

      @@RyanToronto I have been using them with server actions from next especially the isPending, I don't know if it is really a good idea since most server actions are asynchronous

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

      @@emmanuelxs6143 Oh yah with Next.js you can absolutely use async transitions

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

      @@RyanToronto thanks for the update, I appreciate

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

    You voice. Masallah ❤

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

    bruh godly content

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

    Awesome! But, why is this cache function in the React package, and not some Next package, especially if "vanilla" react doesn't even use it?

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

      Great question! Cache is in the main react package because it's useful for any React Server Component to use.

  • @andrei-victor
    @andrei-victor 6 месяцев назад

    Nice . Thank You! I'm using it in a list-feed and I wanted to maintain the scroll position, so I've added `scroll={false}` prop to the Link component and also`router.push("/", undefined, {scroll: false});` on modal close.

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

      Oh awesome! That's great to know!

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

    You forget to say that Middleware slow down app because it rerender every time when you change a route. I am trying to set cookie without midlware but can't find solution

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

      Do you finded some solution?

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

    hello Ryan, how can I use the cache function, I don't know how to get it from the React Canary. Great video by the way that's why I want to use it in my project.

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

      The cache function is only available for React projects that use Server Components. If you're using RSC you can `import { cache } from "react";` and it will work. If you're not using RSC then cache is a no-op and doesn't do anything. Hopefully that helps!

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

      @@RyanToronto hello Ryan, how do I know if I am using RSC? What is an example of a Server Components?

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

      @@RyanToronto hello, it has something to do with the React Canary?

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

    but then, how do i set a cookie from my api ? like i would like to update the session ID of the user of my website, and i can't seem to find how to save a cookie on their browser with the session id from the api request... because : cookies().set( bla bla bla ) will just set the cookie for the response but then it gets lost

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

      cookies.set should do it! Take a look at the docs, you might need some options like how long until it expires: nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options

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

      @@RyanToronto yes, already tried but the request comes from a server component so it only sets the cookie on the reply. Anyway i solved my problem so it doesnt really matter anymore, thanks for the help though :D

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

      @@akopaaa How did you manage to solve it?

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

    What would happen if wrap a transition in a transition? The outer transition holds a state for the inner transition or are they batched together or “unwrapped” like it was a promise passed to a promise constructor? lol idk if that makes sense

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

      Great question! Transitions that wrap transitions are very common and I think saying they are "batched" is the right way of thinking about it. If a transition is inside another transition then neither state update will apply until they are both ready. In other words the state updates happen at the same time for all nested transitions.

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

      @@RyanToronto cool, yea that makes sense, thanks!

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

    Best explaination on earth. Thanks

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

    Ryan, this is a game changer explination. So glad I found this channel. So well broken down