SWR React Tutorial - Complete Course for Beginners

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

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

  • @codegenix
    @codegenix  8 месяцев назад +4

    Between SWR library, React Query or other server state management libraries, what is your choice and why?

  • @josuedavidkennedymamani3576
    @josuedavidkennedymamani3576 11 месяцев назад +7

    I was too lost to use this library but this tutorial fit me like a glove, thank you very much

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

    Brilliant video - this really explains a lot. I love the way you started by trimming out all the crud, and the pace with which you move through the demo. Very helpful!
    One question: In your VSCode you are getting popups telling you what attributes you can choose from (e.g. 36:05). What VSCode extension are you using to give you that?

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

      @intigr8 Thanks so much! To open up the intellisense popups just hit "ctrl + space".

  • @keshavgupta6549
    @keshavgupta6549 Год назад +1

    Thank you sir I asked for this in your last video 🙌🙏

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

    I can't thank you enough. Thank you for this great tutorial on swr
    🥰🥰

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

      I'm really happy that you liked it! Thanks alot

  • @dw31415
    @dw31415 18 дней назад +1

    Nice video. Any recommendations for handling session or other resources that can’t have a Get

    • @codegenix
      @codegenix  16 дней назад

      You're very welcome. What do you mean? Would you explain more?

  • @saudkhan1080
    @saudkhan1080 Год назад +2

    thankyou this was so much helpful and eazy to understand !
    can you please make 1 video about multi-stepper form with input , select , datepicker and radiobuttons with react-hook form and zod or yup validations and percentage styles ..

    • @codegenix
      @codegenix  Год назад

      I really appreciate your positive energy🙏
      How did you read my mind? 😅
      I am currently working on a tutorial about the things that you just mentioned😅.

    • @saudkhan1080
      @saudkhan1080 Год назад

      @@codegenix i just mentioned those things because they are pain in the ass for everyone when dealing with client projects lol
      thankyou thatsgreat , will be waiting for the tutorial 😃

    • @codegenix
      @codegenix  Год назад

      Sure😊, I am planning the new tutorial.

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

    very succint & easy to follow. Thank you 😃

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

      Glad you enjoyed it!

  • @naufalnasrullah6965
    @naufalnasrullah6965 Год назад

    3:15 create components folder inside app dir doesn't affect the route? is there any convention for that with _ at first letter like _components? i'm new so i don't understand

    • @codegenix
      @codegenix  Год назад +1

      It is a good question. The components folder does not affect the routes (as long as there is no page.tsx or layout.tsx or any other next js preserved components) . It is only for better project structure and more readable code.
      The _ underscore was for previous next version (12 and below). Don't mix them up❤️😉

  • @devlhb3474
    @devlhb3474 2 месяца назад +1

    I want to start a new project, and I would like an example of a project structure

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

    You made it easier for understanding definitely. I just have one question, all the GET methods will be in the fetcher functions, and so we don't need a try...catch and nothing related when only getting results? And can we rely on swr for doing all this process for us?

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

      @jasontricolor2978 Yes, exactly

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

      @@codegenix Thank you so much!

  • @mmaarafat
    @mmaarafat 2 месяца назад +1

    Thank you so much. If possible, can you make a video about AWS that we should learn as web developer?

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

      You're very welcome. AWS and almost every provider is banned in my country and I cannot access them

  • @ВладКеся
    @ВладКеся 9 месяцев назад +1

    You make some amazing videos. When are the new ones coming out?

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

      Glad you like them. The next one is React Hook Form + Zod + MUI full course which I'm gonna upload it in a few hours. It is a 4 hours full course, completely FREE!

  • @MohammedSohail-jk1xr
    @MohammedSohail-jk1xr 9 месяцев назад +2

    When wrapping children in a Provider component, which is a client component, the SSR advantage is lost, right?

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

      Using a provider with the 'use client' directive does not mean you are gonna lose SSR advantages. The hydration comes into the play in these situations.

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

    Thanks ❤🎉

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

      You're welcome 😊

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

    Awesome bro

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

      Thank you, I will

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

    So i wrote this export function usePosts(pageIndex) {
    return useSWR(`/api/posts?_limit=1&_page=${pageIndex}`);
    }, but it returns everything from the backend yet I gave it a limit. do I have to the limits on the backend?

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

      What backend are you using? Are you using json-server?

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

    The perfect video, thanks too much

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

      Glad you liked it!

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

    what if the GET method has header authorization how to handle them?

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

      @tnnz9920 You can handle it via fetcher directly in the fetcher file or passing arguments while using useSWR hook then access those parameters in the fetcher.

  • @SarveshOfficial-r7i
    @SarveshOfficial-r7i 7 месяцев назад

    Which is best react query or swr ? I am currently working on my capstone project which needs a good fetching, pooling, kind of realtime updates. For state management i am using recoil. I am confused between choosing react query and swr.
    Can you guide me please

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

      @user-ix5rq4wm8x React query is more powerful for complicated scenarios. SWR is suitable for small to medium size projects.

  • @riteshgsh
    @riteshgsh Год назад

    Hey I learnt Tanstack Query from your video, but I cannot get it right with react-error-boundary and React suspense. It's a bit of work to always do if (isLoading) or if (isError). Having ErrorBoundary and Suspense make it a lot easier.
    I have tried the example of tanstack query docs for the same but couldn't get it right.

    • @codegenix
      @codegenix  Год назад +1

      When a query function results to an error, it tries the query 3 times to get it right finally. If it could not get it right, the data of the query will be undefined through out your project. But you can fix this problem before production. This should not be happened when real user is interacting with your application.
      When a mutation function results to an error, you can handle it in the onError callback in the useMutation hook. For example you can show a popup message that "The product cannot be added to your cart because...". I think there is no need for ErrorBoundary in this situation. Can you give me an example that when the ErrorBoundary is required?

    • @riteshgsh
      @riteshgsh Год назад

      @@codegenix for example when getting data if any error occurs even after 3 tries, then I can contain the error of the component and reset the error or give it a try again button. Whats your suggestion?

    • @codegenix
      @codegenix  Год назад +1

      You can do something like this.
      useEffect(() => {
      if (query.error) {
      // do something
      }
      }, [query.error]);
      also you have access to failureCount by query.failureCount. You can do whatever you want with the error

    • @riteshgsh
      @riteshgsh Год назад +1

      @@codegenix ok, will try it out

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

    Hey Code Genix, are you Iranian? Btw, loved your tutorials...

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

      Are sotoonam. Fadat sham❤️

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

    Thank you very much for this video. May I ask where are you from?

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

      Are dadash chera nemishe😂❤️. Iran karaj

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

      🤣🤣 damet garm movafagh bashi

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

    You're perfect🔥🔥

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

    well done

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

      I'm glad you liked it.

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

    Thank u soo much for this!

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

      Glad you liked it

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

    Tell me if I'm wrong. If you use "use client" in parent component doesn't it make all of the children use client component and not server component, so that means everything is happening on client side. Ps. great video.

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

      I'm really glad you liked it. However, it's important to note that wrapping your entire project in an "use client" directive does not necessarily mean that your whole project will run on the client. You can still execute commands on the server even when your app is wrapped in a "use client" provider. As long as you don't use the "use client" directive at the top of your file, it is considered a React Server Component (RSC), and you can run sensitive commands or communicate with your database in that component. You can test it for yourself by logging a test value. If the value is logged on the server, it means that the code is run on the server and also the same for client.

  • @leviathanxid
    @leviathanxid Год назад

    I have a question, I can already use React Query which I learned from your video, do I have to learn SWR

    • @codegenix
      @codegenix  Год назад +2

      I'm glad that you learnt something❤️
      SWR is more suitable for smaller projects. React query is suitable for large scale applications. You must know the requirements of the project before you decide between these two options.

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

    Extremely great. Thanks a ton!

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

      You're very welcome!

  • @lazy2492
    @lazy2492 Год назад +1

    Nice bro can u make long project use nextjs ,swr and something

    • @codegenix
      @codegenix  Год назад +1

      Yeah sure👍

    • @StephenRayner
      @StephenRayner Год назад +1

      Something = Inngest (event driven architect)

  • @prashlovessamosa
    @prashlovessamosa Год назад +1

    Thanks man.
    I have a question what's coming next on your channel.

    • @codegenix
      @codegenix  Год назад

      I have no idea. The swr tutorial was the idea of my subscribers. You can also suggest the next video.

    • @codegenix
      @codegenix  Год назад +2

      I have react hook form on my mind.

    • @prashlovessamosa
      @prashlovessamosa Год назад

      Yep that's good idea👍

    • @codegenix
      @codegenix  Год назад +1

      I remembered that you also recommended swr on the tanstack video😅. Sure my friend. I have a question. Do you think it is better to combine hook form tutorial with zod? Or just pure hook form tutorial?

    • @prashlovessamosa
      @prashlovessamosa Год назад

      Yes it is better to combine
      ​@@codegenix

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 7 месяцев назад

    thank you

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

      You're welcome

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

    ممنون

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

      You're most welcome!

  • @speedster784
    @speedster784 Год назад

    isnt SWR baked into next js from since 13+ by default?

    • @codegenix
      @codegenix  Год назад

      Thanks for you comment🙏. If you want to fetch data at client level in Next.js application, the Next.js docs suggest that to use SWR or tanstack query library which they are not implemented by default and you must install them as third party libraries.

    • @speedster784
      @speedster784 Год назад

      @@codegenix yes I know that. They also suggested/recommended to fetch data on the server side and pass the data to the client from the server side which helps with SEO and other issues especially if one is using the app router...

    • @codegenix
      @codegenix  Год назад +2

      Yes, exactly. The priority must be to fetch data from the server, create the page, and then pass the page to the user. Imagine an e-commerce website where each page contains product prices, features, and introductions. SEO is very important for each page, and the page must be created on the server for optimal performance.
      However, for example, imagine if the user wants to add a product to their shopping cart. The user expects the shopping cart to be seamlessly updated when the item is added or removed (including mounting and unmounting animations, which are not possible on the server). This scenario can also occur on the server with cache validation, but it is not as user-friendly as client fetching and invalidation.
      The interactions for these types of scenarios are too high. Here, the user experience is more important than SEO. Sometimes, we must strike a balance between SEO and UX.
      Additionally, imagine an ERP dashboard where SEO is not important at all. It is very difficult to always fetch data on the server and pass the page to the user. As a developer, you need to handle the data flow within the application with great care, as handling server fetching and invalidation is very challenging, and you don't have much control over your data while using server data fetching.

  • @Квантоваяопределенность

    That's great.

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

      Glad it was helpful!

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

    Sir, do u have any discord channel?

  • @mohammadzeyghami
    @mohammadzeyghami 3 месяца назад +1

    mashtio o portaradar

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

    You forget to talk about cache, but anyway, excelent video

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

      You're right!

  • @shendrong3695
    @shendrong3695 Год назад

    🎉, im a first?

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

    last infinite scrolling code is invaild
    maybe.....
    incorret code is this code?
    export function useTodos() {
    const getKey = (pageIndex: number, previousPageData: Todo[]) => {
    if (previousPageData && !previousPageData.length) return null;
    return `/todos?_limit=3&_page=${pageIndex + 1}`;
    };
    return useSWRInfinite(getKey);
    }

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

      I checked it, I don't think there is any thing wrong with the snippet that you just provided. Would you provide me more information about the problem and the errors?

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

      @@codegenix I'm so sorry, it just my mistake. Thank you for your great SWR Tutorial!!!

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

      You're very welcome