Why I always use react-query on my react apps

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

Комментарии • 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 2 года назад +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  2 года назад +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 Год назад +2

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

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

  • @YangJimmy-go6no
    @YangJimmy-go6no 7 месяцев назад

    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

  • @BarisPalabiyik
    @BarisPalabiyik 2 года назад +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  2 года назад +1

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

    • @BarisPalabiyik
      @BarisPalabiyik 2 года назад

      ​@@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  2 года назад +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 2 года назад

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

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

    great tutorial cody

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

    simple example but gold explanation. thanks for sharing!

  • @SeibertSwirl
    @SeibertSwirl 2 года назад +4

    Good job babe!!!!

  • @SahraClayton
    @SahraClayton 2 года назад +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  2 года назад +1

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

  • @yfd77
    @yfd77 2 года назад +1

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

    • @WebDevCody
      @WebDevCody  2 года назад +1

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

  • @dhananjaysingh4945
    @dhananjaysingh4945 2 года назад

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

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

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

  • @returncode0000
    @returncode0000 2 года назад

    Great stuff, awesome as always 👍

  • @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?

  • @victorvillacis6764
    @victorvillacis6764 2 года назад

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

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

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

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

  • @gixxerblade
    @gixxerblade 2 года назад

    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 2 года назад

      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 2 года назад

      look into predeterministic fetching

  • @gixxerblade
    @gixxerblade 2 года назад

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

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

  • @khaledsanny4817
    @khaledsanny4817 2 года назад

    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  2 года назад

      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 2 года назад

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

  • @genephillip4233
    @genephillip4233 2 года назад +1

    Is react-query + redux toolkit a good combination?

    • @WebDevCody
      @WebDevCody  2 года назад

      Haven’t used those together before so isk

    • @TannerBarcelos
      @TannerBarcelos 2 года назад +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 2 года назад +1

      @@TannerBarcelos thanks man appreciate it

    • @TannerBarcelos
      @TannerBarcelos 2 года назад

      @@genephillip4233 absolutely 👊🏼

  • @sumanthprabhu11
    @sumanthprabhu11 2 года назад +2

    React Query Vs RTK Query which one is better?

    • @MB-fc9nd
      @MB-fc9nd 2 года назад +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 2 года назад +1

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

  • @yfd77
    @yfd77 2 года назад +1

    Also RQ is great stuff for FE

  • @youssefaserrar2001
    @youssefaserrar2001 2 года назад

    React-query is the GOAT

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

    big thx

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

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

  • @jcros_
    @jcros_ 2 года назад

    why no nextjs?

    • @WebDevCody
      @WebDevCody  2 года назад

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

  • @JEsterCW
    @JEsterCW 2 года назад

    The kid in the bg is on fire 😂🔥

    • @WebDevCody
      @WebDevCody  2 года назад

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

    • @JEsterCW
      @JEsterCW 2 года назад

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

  • @GameKornel
    @GameKornel 2 года назад

    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  2 года назад +1

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

    • @GameKornel
      @GameKornel 2 года назад

      @@WebDevCody Exactly! :)

  • @DuyTran-ss4lu
    @DuyTran-ss4lu 2 года назад

    Amazing

  • @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 9 месяцев назад

    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 2 года назад

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