Five Clever Hacks for React-Query and SWR

Поделиться
HTML-код
  • Опубликовано: 17 ноя 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  • @Norfeldt
    @Norfeldt 2 года назад +3

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

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

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

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

    This is so out of the box and imaginative. Awesome

  • @universecode1101
    @universecode1101 2 года назад +5

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

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

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

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

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

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

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

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

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

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

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

    thinking outside the box and having fun. Love it XD

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

    THE BEST channel I've seen in this website

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

    Woah the SWR global cache is super clever

  • @alex.sprite
    @alex.sprite Год назад +1

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

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

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

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

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

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

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

    Take care and be strong

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

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

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

    Your channel is gem for us 💎💎

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

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

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

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

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

    Thanks a lot, Jack. Great video as per usual

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

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

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

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

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

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

    As usual, very helpful content!. Thanks!!

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

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

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

    watched it to the end!

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

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

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

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

  • @Blue-bb9ro
    @Blue-bb9ro 2 года назад +1

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

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

    Hope to watch a video about fresh and deno soon

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

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

    Great video man, I love your videos

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

    God bless you and your family !

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

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

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

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

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

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

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

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

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

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

  • @DiegoDiaz-pu2pl
    @DiegoDiaz-pu2pl Год назад +1

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

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

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

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

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

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

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

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

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

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

    Another great video, thank you!

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

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

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

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

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

    great content 🎉

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

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

    Thanks for the great video

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

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

    amazing great shared knowledge, thanks man!

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

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

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

    "Bob is your uncle" that cracked me up

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

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

    Fantastic!!!

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

    Thanks so much❤❤❤❤

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

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

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

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

      Github Copilot.

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

    new hair style!

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

    Please use reat with typescript from next video

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

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

    Is it possible to have 2 useSWR requests on the same route? I get conflicting data when i use 2 useSWR in different files

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

      Use a custom hook that wraps the useSWR hook.

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

      @@jherr I wonder how to do this, do you have a written article or visual representation of it? :)

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

      @@StringSwoosh Feel free to ask your question on the DIscord server discord.gg/5juHmkzn . Be sure to follow the #rules and be prepared to talk about what you have tried so far.

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

      @@jherr Thanks! Got it working now, but will join the Discord nonetheless. Peek my head in a bit

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

    Hello, do you mind check your podcast link? I will be happy to listen to your podcast :)

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

      Here is a link to the React Roundup Podcast topenddevs.com/podcasts/react-round-up