Five Clever Hacks for React-Query and SWR

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

КОМЕНТАРІ • 164

  • @thiscris_
    @thiscris_ 2 роки тому +62

    I really hope your channel blow up soon. It is really special to see someone with your level of experience willing to share all the knowledge acquired. You are truly a blessing for the community, I wish you the best, Jack!

  • @joshbaker5566
    @joshbaker5566 2 роки тому +20

    Prayers for you and your wife, Jack...🙏
    Thank you for everything you do.
    The community, myself especially,
    is all the better for your presence.
    Cheers

  • @justice8703
    @justice8703 Рік тому +1

    Thank you so much Jack.
    I've been using swr for a while but didn't know about these hacks.
    After watching the video, I was concerned about the Web Worker example so I went experimenting. I found that, the swr version of this example can also be written like this:

    mutate(() => multiplyNumbers({ a: valueA, b: valueB }), {
    revalidate: false,
    })
    }
    >
    Multiply
    That is, the mutate function from calling useSwr also accepts a callback fn that returns a promise.
    Thanks again for this video.

  • @kiranearle5665
    @kiranearle5665 2 роки тому +3

    Stay strong brother! God bless you and your wife!

  • @AJ-sw4qi
    @AJ-sw4qi Рік тому +3

    Thank you Jack for all the special videos on React. I really hope and pray for the good health, prosperity and well-being of you and your family.

  • @briandev8
    @briandev8 2 роки тому +6

    Jack your videos have been an inspiration to me and I wouldn't have been able to make this huge career transition into Web Development if not for coders like you who post these free instructional videos for everyone. I'm 41 and just started my first Web Development job 3 months ago. I've wanted to start making youtube videos so I too could give back something to this community that has helped me make a career change that will affect my kids' future. Thank you so much Jack, and I wish you and your family the best.

    • @jherr
      @jherr  2 роки тому +1

      That's really great! Thank you so much for watching and good luck in your career!

  • @belmo_
    @belmo_ Рік тому +1

    You are helping a lot of junior/senior reactjs devs around the world. I just wanted to so my appreciation for your work. Thanks.

  • @LarsEjaas
    @LarsEjaas 2 роки тому +9

    Really great video Jack! Thoughts go out to you and your wife.
    I personally have worked with Apollo Client for global state management. Works really well!
    Started out with Redux toolkit, but had to optimize bundlesize and this was a straightforward solution, as I already used Apollo Client for data fetching.

  • @marinagheorghe9636
    @marinagheorghe9636 2 роки тому +1

    I just started with react-query and this video is gold. Thank you, thank you, thank you 😊

  • @snakeplisken4442
    @snakeplisken4442 2 роки тому +1

    Got your channel recommended, and I’m blown away by your quality content. Well explained, good sound, not too basic. All in all great content. Keep it up!
    And to you and your wife - get well soon!

  • @tsooooooo
    @tsooooooo 2 роки тому +1

    You're the man. I've been using react and react-query since their releases but learned something today!

  • @j0hannes5
    @j0hannes5 2 роки тому +4

    For global state management I have RQ for server state.
    I have a ViewConext for toasts, modals, errors... and a AuthContext. So they have their isolated purpose.
    I also use Valtio, which I am a big fan of.
    I liked to say that using multiple state management tools at the same time is not a crime. Cause you can make sure that each has their own purpose. And also each can be separated - eg multiple valtio stores or multiple react contexts or different finite state machines. Using state management libraries is essentially choosing among a tool-box of patterns to choose for the right job.
    (Or if you don't have a job yet, but quickly want to store something globally - I like to use a "generalStore" in valtio)
    BUT the thing is - they can get tangled with each other.
    Especially with local React state.
    It can get confusing when you have different UI state shared among components. Do you keep it local and pass it down? Do you put it into the corresponding valtio store? Should I just put everything that is related to the "section" functionality into my sectionUIStore? Or try to entertain the low priority motivation of keeping state as local as possible. (let's face it - who needs reusable components anyway? just copy-paste to create a new one)
    Then you bring in React Query, thinking: "this is just for server state".
    But what if you are building and using an object in a component (or some global store) and you’re not sending it (back) to your server until the object is ready?
    A simple example of this would be a form.
    There is a motivation to keep it inside the QueryClient Cache. So the idea is to setQueryData("correctKey"). But you also need to make sure the the useQuery("correctKey") is not overwriting it. Or you temporarily bring the state away from React Query into local state before mutating the server.
    As soon as I also had to bring in a state machine to handle a part of the "section" functionality, the ball dropped. The state machine has its own context. But it is dependent on local state AND on state within the valtio sectionUIStore. This is too much. This is not "keep it simple stupid".
    My problem is less with those external tools.
    But more with the fact that local react state is entangled with it all.
    The idealist in me is both happy that React is very unopinionated about many things and lets the ecosystem compete for better solutions. But also frustrated that there is no one-place-to-rule-all-state. Including server state. I would like to question the general motivation to keep state local.

  • @hasanmothaffar3134
    @hasanmothaffar3134 2 роки тому +1

    Respect for providing the article link in the description. Also, thank you for these informative videos!

  • @awaisahmad2065
    @awaisahmad2065 2 роки тому +1

    I love you Jack!!! Your video content covers everything that is typically not available for free. Moreover, we get an insight of mindset of an experienced engineer. I will pray for you and your family in my Friday prayer!!

  • @thehaptiK
    @thehaptiK 2 роки тому +3

    Happy to see you were able to find some time to produce another informative video. I wanted to let you know I'm giving blood Thursday. I do it once a year, but now after watching the first few minutes of your video I'm considering doing it more often. Stay strong Jack, the world needs more men like you. ❤to your family.

    • @jherr
      @jherr  2 роки тому +2

      Thank you so much. Hearing that you will donate blood gave my wife a tear of joy.

  • @AbdelhameedG
    @AbdelhameedG 2 роки тому +2

    Thank you, Jack, seriously man from the bottom of my heart, your tutorials helped me become a way better developer, thank you and please continue doing that, if you have a paid course one day I will definitely buy it.

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

    This is an awesome video! I worked with SWR on a project several months ago and it came to be very handy!

  • @temoncher
    @temoncher 2 роки тому +3

    Thank you for useful tips! But a small correction on 14:10, functor is not a function that creates functions. Function that creates functions (or takes functions as arguments or both) is a higher order function. A functor is a container of some type T that, when subjected to a function that maps from T→V, yields a container of type V. A simple examples of functors can be Arrays or Lists, more sophisticated ones are Futures(aka Promises) or Options(fancy nullable containers).

    • @jherr
      @jherr  2 роки тому +2

      Fair enough. My mistake.

  • @yanksyoon1795
    @yanksyoon1795 2 роки тому +1

    Glad to hear your wife recovering! Thanks for the awesome content!

  • @avneet12284
    @avneet12284 2 роки тому +1

    This is so out of the box and imaginative. Awesome

  • @dertuman
    @dertuman 2 роки тому +1

    Man I found your channel a few days ago and I loved it. You're awesome! Like someone else said, make a course for senior developers, covering complex and big projects, where the starting point of the course is to actually download a big template file with structures similar to that we get in the industry, from git workflow to typescript, I would definitely pay at least $50 dollars for that and I'm just thousands of others would too. Good luck with everything!

  • @samithafernando6432
    @samithafernando6432 2 роки тому +1

    Such a good tutorial. It's amazing to see how things got improved in React world in last 5 years

  • @ridhwwww
    @ridhwwww 2 роки тому +1

    Thank you Jack,
    Prayers for your family and your wife.

    • @jherr
      @jherr  2 роки тому +1

      Thank you! She is doing a lot better!

  • @wagnermoreira786
    @wagnermoreira786 2 роки тому

    THE BEST channel I've seen in this website

  • @paraschitrakar8764
    @paraschitrakar8764 Рік тому

    Thanks!

    • @jherr
      @jherr  Рік тому

      Wow! Thank you do much!

  • @Norfeldt
    @Norfeldt 2 роки тому +3

    Very nice walkthrough, Jack. I wish you and your family the best ❤️

  • @learnwithabdulbari
    @learnwithabdulbari 2 роки тому +6

    Really Amazing. A suggestion can you please make the same video using rtkquery. The same sequential is quite hard with rtkquery as well as dynamic fetching like you have a component that fetch based on the props from different endpoints

  • @fayazansari5295
    @fayazansari5295 Рік тому +1

    Hi @jack, really appreciate your hard work. I watch your videos most of the time and it is really helpful. Please keep updating the new videos. Hope your wife will get well soon.

  • @Littlebfh
    @Littlebfh 2 роки тому +1

    awesome content as always. much love to you and your wife, im glad she is getting better

  • @kmylodarkstar2253
    @kmylodarkstar2253 2 роки тому +1

    Wish you the best, thanks for your time, really appreciated Jack. Thanks for sharing

  • @johngregoryfuntera670
    @johngregoryfuntera670 2 роки тому

    Thank you so much Jack I do hope you make an advance React/Next Js course. I would glad to pay and subscribe if ever you will made that :)

    • @jherr
      @jherr  2 роки тому

      Wow! Thank you so much!

  • @shubhamlatiyan7972
    @shubhamlatiyan7972 2 роки тому +2

    Thank you jack, for every awesome video, you are a good man, Prayers for you

  • @shanabunny
    @shanabunny 2 роки тому +1

    I have learned a lot from your videos, and I always look forward to new ones. Thank you and best of my wishes to you and your family.

    • @jherr
      @jherr  2 роки тому

      Thanks! To you as well!

  • @rinotovar327
    @rinotovar327 Рік тому +1

    Thank you for empowering us developers to be the developers we want to be.

  • @teflonhav
    @teflonhav Рік тому

    Prayers for you guys. Thank you for the content and service you continue to provide 🙏🏾

  • @alex.sprite
    @alex.sprite Рік тому +1

    Great content! Thank you and I'm sending more positive energy back!

  • @jubalm
    @jubalm 2 роки тому +1

    hey, you might be working with the same backend guys im with because this IS exactly how they model APIs 🤣 once again, nailed it. thank you so much

  • @alexandprivate1
    @alexandprivate1 2 роки тому +1

    As usual Jack, excellent content, hope your wife gets better soon man! Sending prayers champ

  • @elamandeep
    @elamandeep 2 роки тому +2

    Your channel is gem for us 💎💎

  • @oumardicko5593
    @oumardicko5593 2 роки тому +1

    thinking outside the box and having fun. Love it XD

  • @karsongrady
    @karsongrady 2 роки тому +1

    Thanks a lot, Jack. Great video as per usual

  • @sarahelizabeth1279
    @sarahelizabeth1279 2 роки тому

    Thank you for the great content. Sending lots of ❤️ and healing to your family.

  • @trenthm
    @trenthm 2 роки тому +1

    Great video, again! We don't deserve content this good lol Please keep it up!

  • @permanar_
    @permanar_ 2 роки тому +1

    Do you think you care to deep deeper about profiling or something like optimization?
    Like when is the bare minimum condition we should start to use React.memo (or probably useCallback, useMemo, etc) or probably something like that?
    I still find this topic really interesting but has less resources to learn especially on how do we debug using Profiler at its fullest ability.
    Thanks as always!!

  • @HabtamuDesalegn
    @HabtamuDesalegn 2 роки тому +1

    As usual, very helpful content!. Thanks!!

  • @rohithchittibommala2002
    @rohithchittibommala2002 2 роки тому +2

    Take care and be strong

  • @universecode1101
    @universecode1101 2 роки тому +5

    React Query is an amazing resource, which I didn't know before ... Thanks Jack as always 😊

  • @PeterJaffray
    @PeterJaffray 2 роки тому +1

    You are a good person :) Thank you for everything you do too

  • @eleah2665
    @eleah2665 2 роки тому +1

    I love the idea of using react-query as a global state manager. I'd like to experiment with it. I thought it specifically had to be fed an async function as the data source..

  • @alii4334
    @alii4334 2 роки тому +1

    watched it to the end!

  • @jasonma1904
    @jasonma1904 2 роки тому

    I got a question and I haven't seen anyone ask. For GlobalState.tsx line 7 (video 38:00). If you pass the key and initData but use a hard-coded key instead of using key props, what is the point of passing the key? Or if I miss something? Thank you for your awesome tutorials as always.

  • @paladinuserfem
    @paladinuserfem 2 роки тому +1

    Great video man, I love your videos

  • @LeonelViera
    @LeonelViera 2 роки тому +1

    Excellent content!
    Side question: what do you use in some of your videos to draw on top of your screen/code? Like in the trpc video.

    • @jherr
      @jherr  2 роки тому +1

      I use Screenbrush and a commodity drawing tablet from Gaomon.

  • @sean9829
    @sean9829 2 роки тому +1

    Hey Jack. Dig your videos. Can you do one about Hasura?

  • @abrahamanakagung4279
    @abrahamanakagung4279 2 роки тому +1

    Great ideas you have here. It make me want to explore some more :). btw why are you still using cra instead of vite based react? Thanks and hope the best for your family

    • @jherr
      @jherr  2 роки тому +1

      Thanks! About vite, habit mainly.

  • @prasad_yt
    @prasad_yt 2 роки тому +1

    God bless you and your family !

  • @loquek
    @loquek 2 роки тому +1

    Another great video, thank you!

  • @MrDavidification
    @MrDavidification 2 роки тому +1

    Woah the SWR global cache is super clever

  • @abdulazeezolanrewaju843
    @abdulazeezolanrewaju843 Рік тому

    Thank you very much Jack
    Please what font do you use for the vscode

  • @spongebob93lover
    @spongebob93lover Рік тому

    Very interesting video! Would love to see a new video about swr 2.0:) also, I’m very curious about the global state part, many suggested that it’s rather a server state manager than a client (UI) state manager. What is your take on this? Should I combine with other client state manager for complex application? If so, do you have experience which one is the best to integrate with swr and nextjs?

  • @ESArnau
    @ESArnau 2 роки тому +2

    20:40 why don't just return log instead of a function that returns log?

    • @jherr
      @jherr  2 роки тому +3

      Because if useQuery called subscribeToLog over and over again it would create a new timer and a new log each time.

  • @electroheadfx
    @electroheadfx 2 роки тому +1

    amazing great shared knowledge, thanks man!

  • @Blue-bb9ro
    @Blue-bb9ro 2 роки тому +1

    I adore you Jack, prayers to you and your wife.

  • @XavierGoncalves89
    @XavierGoncalves89 2 роки тому +1

    At work, we have to make 4 requests in order to get all the info needed to display a list. Only the first one is mandatory and will cause the app to display an empty state if it fails, the other 3 have logic and verifications to be made before the requests are made and add data to the list returned from the first request, we also want the data from those requests to be available in different components/hooks. At first, I thought the "single await function" approach was enough but the further I dig into the old code, the more I think that creating a giant "useMultipleQueries" hook is the way to go, despite being a pain in the ass to write.

    • @jherr
      @jherr  2 роки тому

      I think a single react-query might still work since you can put it in a shared hook and then reuse that hook and I _think_ react-query will reuse the result because the name of the query is the same.

  • @sangminhong1804
    @sangminhong1804 Рік тому +1

    Thanks so much❤❤❤❤

  • @theyreMineralsMarie
    @theyreMineralsMarie 2 роки тому +2

    How does using the query client to set data effect component rendering? The QueryClientProvider wraps the entire application, which leads me to believe the entire app would re-render when setting data.

    • @jherr
      @jherr  2 роки тому

      My guess is that any useQuery will check on any provider changes and will force a re-render if the corresponding key has changed.

  • @mytvhome7394
    @mytvhome7394 Рік тому

    Hi Jack. What do you prefer? SWR or ReactQuery?

  • @--VICKY-
    @--VICKY- Рік тому

    Can you please explain that how will you start learning new stuffs, also how you find these learning asking about research for particular task... Pls reply sir

  • @ryanle4059
    @ryanle4059 2 роки тому +2

    Hi Jack, thank you for your video. I have a question about GlobalState example, how to get the initial value for react-query version?
    If I do {enabled: false} that function is not gonna run so the initData cannot be populated.

    • @jherr
      @jherr  2 роки тому +1

      Yeah, that's why I do the data ?? initialData. Actually, I think I forgot that in the code. Do `.data ?? initialData`.

    • @ryanle4059
      @ryanle4059 2 роки тому

      @@jherr got it.

  • @miguelyoutube100
    @miguelyoutube100 2 роки тому +1

    Thanks for the great video

  • @codezero6023
    @codezero6023 2 роки тому +1

    I am so sorry Jack. You and family are in my prayers

  • @NelA-zd9dk
    @NelA-zd9dk 2 роки тому +1

    Hi, in the stopwatch example, createStopwatch function. Why do we want createStopwatch to return a function, instead of just returning the calculation?

    • @jherr
      @jherr  2 роки тому

      Because we need a function that you can call to get the current time. And not just the current time at the point at which we created the timer, which would always be zero.

  • @sadev0
    @sadev0 2 роки тому +1

    great content 🎉

  • @dijup
    @dijup 2 роки тому

    I am using react query to fetch data, I want to combine it will some kind of offline storage. What will be the best way to do it? Should I use asyncstorage or SQLite and how can I combine it for better control on data.

  • @rajesh-royal
    @rajesh-royal 2 роки тому +2

    Copilot is fun 🤘

  • @abdelhameedhamdy
    @abdelhameedhamdy 2 роки тому +1

    Hope to watch a video about fresh and deno soon

  • @damiancardozodelgado2101
    @damiancardozodelgado2101 2 роки тому +1

    Hello sir, I hope all is good, I just wanted to ask, why are you using Yarn instead of npm ? just curious
    Thanks for the great content

    • @jherr
      @jherr  2 роки тому +1

      I switch back and forth between yarn, npm, and pnpm fairly regularly now. They all have roughly the equivalent feature set and performance as far as the features that I use.

    • @damiancardozodelgado2101
      @damiancardozodelgado2101 2 роки тому

      @@jherr was doing the same , and i do not find any good reason to pick one in particular

  • @DiegoDiaz-pu2pl
    @DiegoDiaz-pu2pl Рік тому +1

    Twenty-two houndred is equal to 2200? My mind just boom.
    Pd. Great video 🤟🏼

  • @rickhoro
    @rickhoro Рік тому

    So sorry to hear about your wife. My prayers to you and your family.

  • @klin-coders9374
    @klin-coders9374 2 роки тому +1

    My thoughts go out to you and you wife. she will come out strong. Thank you for your selflessness

  • @joeyywill1234
    @joeyywill1234 2 роки тому +1

    All the best for your wife and yourself/friends/family!

  • @bennydaniels4153
    @bennydaniels4153 2 роки тому +1

    Any know what theme he's using? Looks dope

    • @jherr
      @jherr  2 роки тому +2

      Night Wolf [black] usually with Operator Mono or JETBrains Mono

  • @viniciusataidedealbuquerqu2837
    @viniciusataidedealbuquerqu2837 2 роки тому +2

    great video as always. I just would like to remind to not show personal info like your real coordinates.

  • @aregbesolajohn5281
    @aregbesolajohn5281 2 роки тому +1

    Awesome video as always Jack. My thoughts are with you and your wife 🙏❤️❤️🙏
    Q: how did you get the geolocation navigator API to work on your localhost 🤯 i once got stuck while working with it because the docs says it only works over HTTPS and not HTTP (which I reckon localhost is) ?

    • @jherr
      @jherr  2 роки тому +1

      Yeah, there was an alert for me the first time, but after that it worked.

    • @aregbesolajohn5281
      @aregbesolajohn5281 2 роки тому

      Okay 👍

  • @teknolovedigital
    @teknolovedigital Рік тому

    May God bless you and your family all the time..

  • @vucaotan9903
    @vucaotan9903 2 роки тому +1

    Fantastic!!!

  • @AuraOfMachines
    @AuraOfMachines 2 роки тому

    "Bob is your uncle" that cracked me up

  • @shin5302
    @shin5302 2 роки тому +1

    Should we do the same thing in next js if we have multiple query request?

    • @jherr
      @jherr  2 роки тому

      With NextJS the multiple request thing becomes a lot easier as it's just the implementation of getServerSideProps. That's a simple function and it doesn't have the same hooks based architecture as a component. So you can just make multiple requests, await them, and then finally return the props to the component, and so the multiple request thing is naturally simplified there.

    • @shin5302
      @shin5302 2 роки тому

      @@jherr Thank You, Jack

  • @shasankkumar7246
    @shasankkumar7246 Рік тому

    I am already using Zustand for global state management and now I am implementing React Query, what do I do? It is a very big project as well. Upon that, it says that onSuccess, onError and onSetteled are deprecated, so I am conflicted to how do I set query fetched data to zustand states, do I use useEffect again, which again defeats the purpose of using react query and worry about setState in useEffect. what is the best way to approach this. Thanks in advance.

  • @ESArnau
    @ESArnau 2 роки тому

    I dont understand what does react-query add, for fetching data... can you explain?

  • @al3xdodo
    @al3xdodo 2 роки тому +1

    Thank you, Jack! I hope that from all of my heart your wife to come back to a such of good MAN! God bless you both!

    • @jherr
      @jherr  2 роки тому

      She is doing a lot better. Thank you for the well wishes.

    • @al3xdodo
      @al3xdodo 2 роки тому

      @@jherr I’m very happy to hear that!

  • @greendsnow
    @greendsnow 2 роки тому +1

    new hair style!

  • @snk263
    @snk263 2 роки тому +1

    gold!

  • @hk_build
    @hk_build 2 роки тому

    Thanks for great content!!
    Can you make a video on micro front end where react component is exposed wich is dependent on redux store and middle wares such as redux saga???

    • @jherr
      @jherr  2 роки тому

      Nope. I'm not going to do that because, as I believe we have discussed,. I don't think it's a good idea to have a large shared Redux store between MFEs.

  • @FalconTheFries
    @FalconTheFries 2 роки тому

    Hey Jack, you didn't really explain why enabled to be be false in State Management use case. Can you please explain it? Thanks

    • @jherr
      @jherr  2 роки тому

      So that it doesn't re-run the query function to update the cache, which resets the value to its initial value. My bad, I'm sorry, I realized late that I didn't cover that.

  • @dc33333
    @dc33333 Рік тому +1

    Oh gee. You are such a good person Jack. I hope the wife is ok.

    • @jherr
      @jherr  Рік тому +1

      She is fully recovered and doing great. Thank you so much for asking!

  • @thedevelopermind
    @thedevelopermind 2 роки тому +1

    Hi Jack, can you tell me your code autocomplete's name?

    • @jherr
      @jherr  2 роки тому

      Github Copilot.

  • @viniciusataidedealbuquerqu2837
    @viniciusataidedealbuquerqu2837 2 роки тому +1

    that ending 😂😂😂😂😂😂😂

  • @waleedsharif618
    @waleedsharif618 2 роки тому +1

    Are you going to pay for github copilot ? Cuz its free for 3 weeks now

    • @jherr
      @jherr  2 роки тому

      I am actually. But my React Round Up co-hosts are not going to, so... opinions vary.

  • @carlosricardoziegler2650
    @carlosricardoziegler2650 2 роки тому

    So nice , some approach to use react-query with graphql?

    • @jherr
      @jherr  2 роки тому +1

      Oh yeah, that all works. graphql is really just a different way of formatting the request payload.

    • @carlosricardoziegler2650
      @carlosricardoziegler2650 2 роки тому

      @@jherr nice to know I didn’t but I need to test hahah maybe it is good theme for video haha