SWR React Tutorial - Complete Course for Beginners

Поділитися
Вставка
  • Опубліковано 23 гру 2024

КОМЕНТАРІ • 100

  • @codegenix
    @codegenix  7 місяців тому +4

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

  • @josuedavidkennedymamani3576
    @josuedavidkennedymamani3576 10 місяців тому +5

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

  • @intigr8
    @intigr8 5 місяців тому +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  5 місяців тому

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

  • @jasontricolor2978
    @jasontricolor2978 6 місяців тому +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  6 місяців тому

      @jasontricolor2978 Yes, exactly

    • @jasontricolor2978
      @jasontricolor2978 6 місяців тому

      @@codegenix Thank you so much!

  • @muratasarslan2359
    @muratasarslan2359 4 місяці тому +1

    very succint & easy to follow. Thank you 😃

    • @codegenix
      @codegenix  4 місяці тому

      Glad you enjoyed it!

  •  7 місяців тому

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

    • @codegenix
      @codegenix  7 місяців тому

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

  • @mmaarafat
    @mmaarafat Місяць тому +1

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

    • @codegenix
      @codegenix  Місяць тому

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

  • @saudkhan1080
    @saudkhan1080 11 місяців тому +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  11 місяців тому

      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 11 місяців тому

      @@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  11 місяців тому

      Sure😊, I am planning the new tutorial.

  • @devlhb3474
    @devlhb3474 22 дні тому +1

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

  • @MohammedSohail-jk1xr
    @MohammedSohail-jk1xr 8 місяців тому +2

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

    • @codegenix
      @codegenix  8 місяців тому

      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.

  • @keshavgupta6549
    @keshavgupta6549 11 місяців тому +1

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

    • @codegenix
      @codegenix  11 місяців тому

      Most welcome 😊❤️

  • @naufalnasrullah6965
    @naufalnasrullah6965 11 місяців тому

    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  11 місяців тому +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❤️😉

  •  7 місяців тому

    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  7 місяців тому

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

  • @tnnz9920
    @tnnz9920 6 місяців тому

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

    • @codegenix
      @codegenix  6 місяців тому

      @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.

  • @riteshgsh
    @riteshgsh 10 місяців тому

    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  10 місяців тому +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 10 місяців тому

      @@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  10 місяців тому +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 10 місяців тому +1

      @@codegenix ok, will try it out

  • @agustinpaz847
    @agustinpaz847 8 місяців тому +1

    The perfect video, thanks too much

    • @codegenix
      @codegenix  8 місяців тому +1

      Glad you liked it!

  • @SarveshOfficial-r7i
    @SarveshOfficial-r7i 6 місяців тому

    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  6 місяців тому

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

  • @ВладКеся
    @ВладКеся 7 місяців тому +1

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

    • @codegenix
      @codegenix  7 місяців тому

      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!

  • @hsuwai-v8v
    @hsuwai-v8v 9 місяців тому +1

    Thanks ❤🎉

    • @codegenix
      @codegenix  9 місяців тому

      You're welcome 😊

  • @EhsanKhanahmadi
    @EhsanKhanahmadi 21 день тому +1

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

    • @codegenix
      @codegenix  19 днів тому +1

      Are dadash chera nemishe😂❤️. Iran karaj

    • @EhsanKhanahmadi
      @EhsanKhanahmadi 18 днів тому +1

      🤣🤣 damet garm movafagh bashi

  • @leviathanxid
    @leviathanxid 11 місяців тому

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

    • @codegenix
      @codegenix  11 місяців тому +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.

  • @memduhcevik
    @memduhcevik 8 місяців тому

    Awesome bro

    • @codegenix
      @codegenix  8 місяців тому

      Thank you, I will

  • @nikolajelic892
    @nikolajelic892 7 місяців тому +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  7 місяців тому

      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.

  • @prashlovessamosa
    @prashlovessamosa 11 місяців тому +1

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

    • @codegenix
      @codegenix  11 місяців тому

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

    • @codegenix
      @codegenix  11 місяців тому +2

      I have react hook form on my mind.

    • @prashlovessamosa
      @prashlovessamosa 11 місяців тому

      Yep that's good idea👍

    • @codegenix
      @codegenix  11 місяців тому +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 11 місяців тому

      Yes it is better to combine
      ​@@codegenix

  • @dmltdev
    @dmltdev 8 місяців тому

    Extremely great. Thanks a ton!

    • @codegenix
      @codegenix  8 місяців тому

      You're very welcome!

  • @alikeshtkar5662
    @alikeshtkar5662 8 місяців тому

    You're perfect🔥🔥

  • @allensmith8503
    @allensmith8503 7 місяців тому

    Thank u soo much for this!

    • @codegenix
      @codegenix  7 місяців тому

      Glad you liked it

  • @yasin_khadem
    @yasin_khadem 6 місяців тому +1

    well done

    • @codegenix
      @codegenix  6 місяців тому

      I'm glad you liked it.

  • @speedster784
    @speedster784 11 місяців тому

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

    • @codegenix
      @codegenix  11 місяців тому

      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 11 місяців тому

      @@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  11 місяців тому +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.

  • @msarlak1512
    @msarlak1512 9 місяців тому

    ممنون

    • @codegenix
      @codegenix  8 місяців тому +1

      You're most welcome!

  • @bahramiwd4812
    @bahramiwd4812 4 місяці тому +2

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

    • @codegenix
      @codegenix  4 місяці тому

      Are sotoonam. Fadat sham❤️

  • @devT44
    @devT44 7 місяців тому

    Sir, do u have any discord channel?

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 6 місяців тому

    thank you

  • @lazy2492
    @lazy2492 11 місяців тому +1

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

    • @codegenix
      @codegenix  11 місяців тому +1

      Yeah sure👍

    • @StephenRayner
      @StephenRayner 11 місяців тому +1

      Something = Inngest (event driven architect)

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

    That's great.

    • @codegenix
      @codegenix  9 місяців тому

      Glad it was helpful!

  • @mohammadzeyghami
    @mohammadzeyghami 2 місяці тому +1

    mashtio o portaradar

  • @harleyjoker6456
    @harleyjoker6456 9 місяців тому

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

  • @shendrong3695
    @shendrong3695 11 місяців тому

    🎉, im a first?

    • @codegenix
      @codegenix  11 місяців тому

      Yes my dear friend😁

  • @leciel87
    @leciel87 7 місяців тому +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  7 місяців тому +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 7 місяців тому

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

    • @codegenix
      @codegenix  7 місяців тому

      You're very welcome