Why I always use react-query on my react apps

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ต.ค. 2022
  • 💬 Discord / discord
    🤑 Patreon / webdevjunkie
    🔔 Newsletter eepurl.com/hnderP
    📁. GitHub github.com/codyseibert/youtube
    My VSCode Extensions:
    - theme: material community high contrast
    - fonts: Menlo, Monaco, 'Courier New', monospace
    - errors: Error Lens
    - extra git help: Git Lens
    - tailwind css intellisense
    - indent rainbow
    - material icon theme
    - prettier & eslint
    - ES7+ React Snippets

ความคิดเห็น • 65

  • @Thelukkest
    @Thelukkest ปีที่แล้ว +1

    Omg just discovered this. Idk if I lived behind the moon or smth not finding this library sooner. It looks so good!

  • @TheRcfrias
    @TheRcfrias ปีที่แล้ว +3

    Great video!, My first noob mistake was to try to use React-Query for "Everything", but the truth is that things like a login or analytic reporting requests should probably don't need to use it. So it's important to identify where this will give us a real benefit.

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +6

      I think you can still use mutations for login if you wanted that built in isLoading flag or error boolean if stuff goes wrong

    • @eshw23
      @eshw23 10 หลายเดือนก่อน +2

      Definately need it for logging in, maybe not for small get requests but still theres nothing wrong with using it for everything

  • @returncode0000
    @returncode0000 ปีที่แล้ว

    Great stuff, awesome as always 👍

  • @rhenaldkarrel
    @rhenaldkarrel ปีที่แล้ว

    simple example but gold explanation. thanks for sharing!

  • @dhananjaysingh4945
    @dhananjaysingh4945 ปีที่แล้ว

    Oh thank god…you just solved an issue i have been looking for like an hour.❤❤❤

  • @YangJimmy-go6no
    @YangJimmy-go6no 3 หลายเดือนก่อน

    Hi I am still quite confused. Where do you set the todo as a query key, and it is a github repository for this video? I couldn't find it. Thank u

  • @erik9817
    @erik9817 ปีที่แล้ว +1

    What about using a real-time databases like firebase? Is there any point in using react query with that? Firebase real-time database notifies of changes and gives the latest data to clients.

  • @tarushchandra8993
    @tarushchandra8993 2 หลายเดือนก่อน

    great tutorial cody

  • @SahraClayton
    @SahraClayton ปีที่แล้ว +1

    Hi Cody, great video. i haven't got to use Nextjs yet, but I have used React and React-Query together, when using React-Query with Nextjs does that mean you don't have to fetch data with getServerSideProps function or am I way off the mark

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +1

      You’d still need get server side props if you plan to do ssr

  • @nikako1889
    @nikako1889 ปีที่แล้ว

    do you use react context or redux toolkit for state management?

  • @SeibertSwirl
    @SeibertSwirl ปีที่แล้ว +4

    Good job babe!!!!

  • @victorvillacis6764
    @victorvillacis6764 ปีที่แล้ว

    YESSSS I found this and I LOVE IT!!!!

  • @BarisPalabiyik
    @BarisPalabiyik ปีที่แล้ว +6

    Next13 seems to handle the server side fetching and loading states but for mutations(Post reqs) in client side components the tanstack query will keep on providing greatness still. React says it's the official fetching method now for react but it's unfinished I think, they should have provide an easy way to mutate data too, fetching wasn't a biggie after react query or swr anyways. Can you make a video where a client side component mutates data with prisma "in" the component?? I think it would provide a great value.

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +1

      I probably would not write prisma calls inside a component, that sounds like going back to php

    • @BarisPalabiyik
      @BarisPalabiyik ปีที่แล้ว

      ​@@WebDevCody Exactly, I feel like it opened the door for, Wordpress like plugins and widgets to be developed. Which is a great news imo. I used Wordpress for years, would love a tool that is faster, more secure, more agile and not written in PHP :).

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +1

      @@BarisPalabiyik oh sorry I meant to say would not 😅 I like decoupling my views from my data via api calls. Having prisma directly in components seems like a code smell

    • @BarisPalabiyik
      @BarisPalabiyik ปีที่แล้ว

      @@WebDevCody I see, smart layouts can be value for new people who want to go full-stack I feel and maybe even for big apps. Because seperation of concerns is handled by component base system, I didn't like the MVC codebases where I am all over the place. Fetching in nested layouts is what they are pushing now, and the idea of standardized ecosystem with tailwind, prisma, next where you can just drop a directory and have a fully fledged widget or mini-fullstack-app that you can put wherever in your app sounds delicious.

  • @khaledsanny4817
    @khaledsanny4817 ปีที่แล้ว

    Great video DevJunkie, am also using react-query, and am facing an issue, I want to "await" a queryKey variable... like a token from Oauth... when the component is initialized Oauth is triggered but react-query doesnt wait the auth.token (for instance)to be available before making the fetch... so the token in fetch() is first null, next undefined and THEN defined... it causes errors in the console... can tell me whats happening ?

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว

      I would just make the callback which does the api request just return null if no token is set. That would prevent a network request and just return some default empty state until token is actually set. You can also tell react query to not automatically fetch by setting enabled false and hAving a useEffect listen for when the token is defined and manually invoke your query

    • @khaledsanny4817
      @khaledsanny4817 ปีที่แล้ว

      @@WebDevCody oh ... ok thanks .... I also though about the second solution... 👏🏾

  • @yfd77
    @yfd77 ปีที่แล้ว +1

    Want to ask does react query with redux tool kit Overkill?

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +1

      I think redux has rtk query you might want to use instead?

  • @teknolovedigital
    @teknolovedigital ปีที่แล้ว

    Your video content is always full of knowledge.
    I want to know, can react query work hand in hand with remix?

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +1

      I’m sure you could use it if needed

  • @henriqueb5637
    @henriqueb5637 ปีที่แล้ว +1

    Nice video!
    I guess most of the companies out there still use more tradicional approaches like redux and all?
    But they also want to hire someone that keeps up with new technologies, right?
    I don't know which approach to use in my portfolio projects...

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +1

      I think people are moving away from redux at this point.

    • @henriqueb5637
      @henriqueb5637 ปีที่แล้ว +1

      ​@@WebDevCody After a few months on the job hunt I can say that you are mistaken.
      Lots and lots of companies from all sizes and countries still using Redux.
      I see Redux as a requirement in job descriptions really often.

  • @omarkraidie
    @omarkraidie ปีที่แล้ว

    If you add a random id to the new todo how can a user instantly delete it after because it has a incorrect id dont you have to get the id from the db for each item?

    • @omarkraidie
      @omarkraidie ปีที่แล้ว

      Correct me if im wrong but I think the optimistic updates is better for deletes?

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว

      Can’t you keep track of that random id inside a variable of the callback to use in the .catch when an error creating goes wrong?

    • @omarkraidie
      @omarkraidie ปีที่แล้ว

      @@WebDevCody Hmm, I never thought of that before. I use MongoDB for by database so in my case I could geberate a unique "_id" with a library and use that?

  • @gixxerblade
    @gixxerblade ปีที่แล้ว

    React query will keep items in cache as long as you don’t fetch another item with a different key. So basically if you’re on the same page but change pages and it runs another query it’ll replace that cache with the new results.

    • @Sapphiamur
      @Sapphiamur ปีที่แล้ว

      Oh that's a good point. I've just learned the basics of redux and was wondering about the differences between these two tools since I've heard query could be used instead of redux? But I don't know much of anything yet :d.

    • @victorvillacis6764
      @victorvillacis6764 ปีที่แล้ว

      look into predeterministic fetching

  • @kelele7173
    @kelele7173 ปีที่แล้ว

    big thx

  • @genephillip4233
    @genephillip4233 ปีที่แล้ว +1

    Is react-query + redux toolkit a good combination?

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว

      Haven’t used those together before so isk

    • @TannerBarcelos
      @TannerBarcelos ปีที่แล้ว +2

      It works but it makes no sense. If you use RTK, using RTK-Query which is redux’ version of “tanstack query” is a no brainer. The api is built in and plays very nicely with the global store. Of course, it’s important to realize how much is really client versus server state. If you’re fetching tons of things and it’s all from the server, you should be using something like Tanstack Query or RTK-Query but you don’t store it in state because it’s not client state. So, to sum it up - I’d not use them together. If you choose the Redux Toolkit route, use the built in API for RTK-Query

    • @genephillip4233
      @genephillip4233 ปีที่แล้ว +1

      @@TannerBarcelos thanks man appreciate it

    • @TannerBarcelos
      @TannerBarcelos ปีที่แล้ว

      @@genephillip4233 absolutely 👊🏼

  • @gixxerblade
    @gixxerblade ปีที่แล้ว

    10:35 you return previous todos if the mutate is unsuccessful

  • @brentryczak
    @brentryczak ปีที่แล้ว

    This was exactly what I was looking for. WHY to use react query

  • @DuyTran-ss4lu
    @DuyTran-ss4lu ปีที่แล้ว

    Amazing

  • @yfd77
    @yfd77 ปีที่แล้ว +1

    Also RQ is great stuff for FE

  • @jcros_
    @jcros_ ปีที่แล้ว

    why no nextjs?

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว

      I use next js as well, but you still need to do dynamic data calls from your client when users do certain interactions

  • @sumanthprabhu11
    @sumanthprabhu11 ปีที่แล้ว +2

    React Query Vs RTK Query which one is better?

    • @MB-fc9nd
      @MB-fc9nd ปีที่แล้ว +4

      both has merits, rtk query can do everything React Query does and has out of box integration with rtk toolkit, and the rtk slice can detect if certain query completed or not and u can do something with it.

    • @rafaelarantes4804
      @rafaelarantes4804 ปีที่แล้ว +1

      If you are stuck with redux, go with rtk. If not, react query is your best choice.

  • @GameKornel
    @GameKornel ปีที่แล้ว

    10:27
    Well, I guess you said it in the very next sentence why we call it "previousX" ;) Basically your sentence before that was wrong :D

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +1

      Yeah , the previous returned in that one function is part of the context for the next.

    • @GameKornel
      @GameKornel ปีที่แล้ว

      @@WebDevCody Exactly! :)

  • @youssefaserrar2001
    @youssefaserrar2001 ปีที่แล้ว

    React-query is the GOAT

  • @JEsterCW
    @JEsterCW ปีที่แล้ว

    The kid in the bg is on fire 😂🔥

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว

      What you talking about Willis? Oh my children who always decide to scream when i record

    • @JEsterCW
      @JEsterCW ปีที่แล้ว

      @@WebDevCody This is typical, no worries kids like to bother parents hah

  • @eshw23
    @eshw23 10 หลายเดือนก่อน

    React query is god like, took me a week to get used to it, and now I never look back

  • @MyGeorge1964
    @MyGeorge1964 ปีที่แล้ว

    Two minutes in and I still don't know why 'I' (not the the guy in the video) would want to use React Query... Help: tell me what problem it will solve that would make my life easier, then tell me how!

    • @WebDevCody
      @WebDevCody  ปีที่แล้ว +2

      Sorry I didn’t provide good examples. Basically in most react apps you’re going to fetch data and need to show a spinner while it’s loading, which means you’ll end up making an isLoading state to track before and after the api request. Request query does that for us. Also, assume you have the same data on 2 components on the page, if they both use the same query, the ui will only make a single api request to get the data. Secondly, if react query has already fetched that data once (navigating back and forth between pages), that data is cached and it’ll be displayed instantly and fetch an updated version of the data behind the scenes.

    • @arpitgoyal1979
      @arpitgoyal1979 ปีที่แล้ว

      @@WebDevCody Thanks for the summary

  • @wvdheuvel2115
    @wvdheuvel2115 5 หลายเดือนก่อน

    Hi Cody, not such a great video. You leave a lot of things open-ended and kind of hint at things but then don't explain them. Such as you mention isLoading and isFetching but don't explain the difference between the two. Are they the same? You seem to use the terms interchangeably. Or fetching the individual todo request, you sort of start explaining it but then realize you don't really remember how and abort the mission alltogether. This means we have to leave the video and search elsewhere.
    Or 'refetchOn WindowFocus' you mention you *believe* it's default is true. It would be good to know this, _before_ recording the video. Again, we come here to learn something, and we find out you don't really know it yourself either. Again the same thing happens with the optimistic update, you say you don't know why to return the previous todos.
    It's understandable you want to keep things concise, but then don't start on tangents you don't explore to the fullest. Just some feedback, do with it what you will.

  • @Pareshbpatel
    @Pareshbpatel ปีที่แล้ว

    A great walk through react-query V4 hilighting some of its great features. Thanks.
    {2022-11-24}, {2023-09-27}