My Favorite Way to Fetch Data in React

  Рет қаралды 67,662

Josh tried coding

Josh tried coding

Жыл бұрын

React couldn't care less how you fetch your data. I use React Query to offload so many concerns we normally have when fetching data. Loading state? Graceful error handling? Caching? It's all possible.
Video links
React query: tanstack.com/query/latest
My links
My GitHub: github.com/joschan21
Discord: / discord

Пікірлер: 146
@ninthsun
@ninthsun Жыл бұрын
Thanks, this was one perfect introduction to react-query in just 15 minutes!!
@developerpranav
@developerpranav 11 ай бұрын
Making hooks using React Query is killer! Thanks for the awesome tutorial!
@ifeanachofavour409
@ifeanachofavour409 9 ай бұрын
Brooo, I love your videos and you've been a part of my success in past few months. Great stuff man. Thanks
@joek696
@joek696 7 ай бұрын
I saw too many videos about this and this is by far the best one! thank you. liked and subscribed.
@user-wp4zy2fd2f
@user-wp4zy2fd2f 3 ай бұрын
Thanks Bro, a perfect video of how to handle data fetching using react-query. waiting for more on react-query, probably part-2
@kamehameha38
@kamehameha38 Жыл бұрын
Just discovered your channel through Theo. Loving your content so far
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Cheers man happy to hear that
@Aidorimuhausu
@Aidorimuhausu 8 ай бұрын
00:04 React Query is a robust data fetching solution that can be implemented in your own React applications. 02:07 Provide a query client context to fetch data across the application. 04:10 React Query allows you to fetch data asynchronously and work with it synchronously 06:12 The data fetched from the query can be of different types 08:12 Using useQuery for data fetching and caching in React 10:13 Mutation is used for changing data, while query is used for getting data. 12:24 Make get requests and dynamically insert post ID in the URL 14:33 React query allows for graceful handling of success and error states
@MilindMishra
@MilindMishra Жыл бұрын
everytime i think of something josh somehow comes up witha tutorial for the same! how do you read my mind! jokes aside, great work pushing out the content, josh! love the work!
@nubian_goat
@nubian_goat Жыл бұрын
Totally! 🎉
@joshtriedcoding
@joshtriedcoding Жыл бұрын
happy to hear that man. means a lot.
@whizzbang7520
@whizzbang7520 10 ай бұрын
Exactly what I was looking for. Nice one!
@nicholassingh138
@nicholassingh138 Жыл бұрын
Love your content bro Coming from svelte and watching how react works. It hurts my head for sure.
@escaper2137
@escaper2137 8 ай бұрын
bruuuuuh where have you been all this time thank you for all your efforts
@michaelmironov3589
@michaelmironov3589 10 ай бұрын
this is so f*in cool because i lost 2 days to figure out how to fetch data with axios and feed it correctly to lightweight charts library, thank you very much!1
@animegeek-011
@animegeek-011 Жыл бұрын
React query is amazing i spent a week trying it, and it's really good
@joshtriedcoding
@joshtriedcoding Жыл бұрын
agreed
@codinginflow
@codinginflow Жыл бұрын
Bruder. Is your app a startup or just some fun project? I also use NextJS + Express but I use SWR
@Luka_brx
@Luka_brx Жыл бұрын
SWR is better option at the moment i would say
@storylineteam
@storylineteam Жыл бұрын
Using react query with axios is a great solution (tanstack also has a great solution for tables). I like to stay away from the Vercel ecosystem as they are forcing everyone to use their platform for deployment, this is why they are making clones of existing packages (swr, router, etc). Also the React Query Developer tools are great!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
they really are, cheers man
@stexorgamingHDx
@stexorgamingHDx Жыл бұрын
D
@vickonsscope6477
@vickonsscope6477 Жыл бұрын
Exactly... Obviously forcing everyone to use their deployment platform..
@nidhishsrivastava4868
@nidhishsrivastava4868 11 ай бұрын
can we use react query with next js
@davidkim2016
@davidkim2016 11 ай бұрын
@@vickonsscope6477 dont use them then? or better yet, become a good enough developer to not rely on their devx and eco
@willxiang25
@willxiang25 Жыл бұрын
great video josh ! and it's interesting that you keep looking left and right 😂
@joshtriedcoding
@joshtriedcoding Жыл бұрын
cheers man, thats how you keep learning
@rahimco-su3sc
@rahimco-su3sc Жыл бұрын
i really like your content !! tanks a lot
@speedster784
@speedster784 Жыл бұрын
What API are you using to transcribe the KZbin video that you briefly demonstrated in the video on the site you working on is it a GPT API or some other API??
@germantellez2710
@germantellez2710 3 ай бұрын
amazing video man thank you!
@dejanobradovic9723
@dejanobradovic9723 11 ай бұрын
Thanks for stunning topic!
@joshtriedcoding
@joshtriedcoding 11 ай бұрын
Cheers man!
@lopuma1990
@lopuma1990 10 ай бұрын
Hello friend 😊, thanks for your content, I speak Spanish and I have found the best react query and zustand content here, after playing it several times because of my bad English 😂 hehehe, one question, do you have a video of zustand and react query together?
@jaroslavhuss7813
@jaroslavhuss7813 Жыл бұрын
Yeah, btw. thank you for this video. Now I can see this is a better approach comparint to what I am using now. Arghhh... I just need to rewrite the app again :D
@joshtriedcoding
@joshtriedcoding Жыл бұрын
OH NO ITS A TRAP! 'I just need this one rewrite' is a big trap my man, be very careful. It might end up in a never ending cycle of rewrites
@gradientO
@gradientO 11 ай бұрын
Best introduction to this!
@jotaroisdarius1918
@jotaroisdarius1918 Жыл бұрын
Hey Josh, do you have any idea on how to force a fallback font in NextJS? I had a problem with the original font which triggered the fallback and I actually liked it more than the original one
@BuyHighSellLo
@BuyHighSellLo Жыл бұрын
just look up what the font is and set that as your default
@Pareshbpatel
@Pareshbpatel 5 ай бұрын
Very nice introductionto React-Query. Thanks. {2023-12-22}
@anonymoussloth6687
@anonymoussloth6687 Жыл бұрын
Is this article project open source? Or will you be creating a whole video where you make this app?
@outroddet_6260
@outroddet_6260 Жыл бұрын
Hey, echt cooles Video. Kannst du mal ein Video darüber machen, wie du genau vorgehst, wenn du nicht NextJS als backend verwendest, sondern dein eigenes mit express? Weil NextJS hat ja von Haus aus schon ein eigenes Backend. Würde mich echt interessieren.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
both approaches are quite similar because after all, nextjs serverless functions are a "spin-off" of express. Not sure how I'd package this into a video, thanks a lot for the suggestion though. Will look into it
@EricFernandoMosqueraVelandia
@EricFernandoMosqueraVelandia Жыл бұрын
Great content bro 🍷🗿!! you are de best!
@jomoc6112
@jomoc6112 Жыл бұрын
great content, i never knew i could handle it this beautifully. please teach me how to reFetch the mutation if the data is still not there, maybe i did it wrong im currently trying it on onSuccess because it is still receiving data.
@satejbidvai
@satejbidvai Жыл бұрын
I am trying to build something using the Next13 appDir. I went through the docs and found the fetch API for data fetching in server side components. So, should I use react-query only for client side components, or for the entire app. I am a bit confused as to when to use what.
@brenosonda8496
@brenosonda8496 Жыл бұрын
I think react-query works only in client since it uses context and hooks,
@natalianatalia1734
@natalianatalia1734 Жыл бұрын
If u use nextjs it is recommended to use Server side component so react hooks will not work. But imo using nextjs fetching is so simple that i wouldnt bother client side components.
@codingcambodia
@codingcambodia Жыл бұрын
What state management do you use. It would be great if You can make a video on reactjs react query and state management for authentication.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
honestly, I came so far just using context, never tried out anything other than zustand. Might be worth looking into tho, heard lots of good about jotai
@BenHuxford
@BenHuxford 3 ай бұрын
I've been reading that React Query is good for state management. Is this not true?
@alexenax1109
@alexenax1109 5 ай бұрын
Loved this video!
@waliahmed3035
@waliahmed3035 Жыл бұрын
Josh can you please make a video of React Query in Next JS server components?
@maxime_spinard
@maxime_spinard 11 ай бұрын
Is it not a better approche if we pass to the hook the api url and the onSuccess and onError functions from the components ? So we can only have two hooks, one for fetching and one for mutations with default onSuccess and onError if nothing has been passed as prop
@istvan.design
@istvan.design 21 күн бұрын
There is an issue with onSucces and onError (they are not reliable), they actually removed them in the latest react query version.
@mathiasriissorensen6994
@mathiasriissorensen6994 9 ай бұрын
I have been used useSWR in the past, but this seems really good. How does it work with Next.js and the app folder considering serverside and "use client" ?
@yarapolana
@yarapolana 9 ай бұрын
I just saw the documentation somewhere not in their official docs. Basically you can make use of the functions with “use server” inside or decouple it to an action.ts file
@mathiasriissorensen6994
@mathiasriissorensen6994 9 ай бұрын
@@yarapolana Thanks. I’ll see how it is going to work.
@nubian_goat
@nubian_goat Жыл бұрын
Josh is hackerman. even with airplane mode on, he have internet.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
hahaha
@shu3684
@shu3684 Жыл бұрын
but this is client-side fetching solution only, right? do you ever use other data fetching methods?
@Dhruv-kumar657
@Dhruv-kumar657 11 ай бұрын
i wanted to use next js only for ssr but i don't know ssr. any video possible on it comparing ssr both react and next
@Sammysapphira
@Sammysapphira 9 ай бұрын
Love the one piece wallpaper
@ardianhotii
@ardianhotii 10 ай бұрын
Can you do a video how to use react-query in nextjs 13.4 app router with data fetching in hooks please , I like your videos so much keep going
@anonymoussloth6687
@anonymoussloth6687 Жыл бұрын
Hi, I am a beginner and I was confused between isLoading provided by react query and loading pages in-built in next js. What is the difference? do they do the same thing?
@antoniors
@antoniors Жыл бұрын
react query's loading just gives you a boolean that you can use to conditionally render some JSX based on it like so: return ( { isLoading && Loading...
@tanjungclan3864
@tanjungclan3864 Жыл бұрын
Josh, are you using state management like redux for all your project?
@nada125love
@nada125love Жыл бұрын
the same question I want to ask about
@tanjungclan3864
@tanjungclan3864 Жыл бұрын
@@abhiramsatpute it's mean, we don't need redux, right?
@abhiramsatpute
@abhiramsatpute Жыл бұрын
@@tanjungclan3864 you don't need redux only when you are storing 'Fetch/Axios' data, for other data like toggling dark/light theme, you might need Redux or even better using Context API.
@tanjungclan3864
@tanjungclan3864 Жыл бұрын
@@abhiramsatpute it's what i do right now
@shakilahmed6870
@shakilahmed6870 Жыл бұрын
​@@abhiramsatpute Redux is not only for fetching data and sharing them among other components.
@chesterrogersjr1737
@chesterrogersjr1737 Жыл бұрын
react-query is the 🐐
@EduardKaresli
@EduardKaresli Жыл бұрын
I'd use React Query if my app isn't using Redux, or RTK Query if I'm using Redux, I think both are awesome.
@rl6382
@rl6382 Жыл бұрын
Why RTK query if using redux?
@EduardKaresli
@EduardKaresli Жыл бұрын
@@rl6382 Because it is already integrated with RTK (Redux ToolKit), why importing other packages when you already havea query library included in RTK?
@MrSadeeq67
@MrSadeeq67 5 ай бұрын
​@@EduardKaresliRTK Query is really best option if you have Redux in the app
@pelazas1
@pelazas1 Жыл бұрын
helpful, thanks!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
cheers man
@333ruka
@333ruka Жыл бұрын
what extension u use for showing the size of a module like that ?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
think its called "import cost" in vscode
@Saltertv
@Saltertv Жыл бұрын
I'm struggling a bit to understand how I can use this to retrieve pre-rendered pages using static or server props. This looks like a good choice for client side rendering and fetching.
@deiminator2
@deiminator2 Жыл бұрын
React query is a hook so you can only use it in the react client, not in the next server
@denissorn
@denissorn Жыл бұрын
I haven't watched the video yet, but he's obviously using Next for that. The API is only for fetching data and business logic. I do wonder why didn't he use Next for this, but I have no experience with it, and my guess is, his estimate was that business logic and API are complicated/important enough to justify the use of another server/separate backend.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
yeah as it's just a hook, this is meant for client use only
@martiananomaly
@martiananomaly Жыл бұрын
Finally I can ditch the ugly useEffect + loading state combo.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
oh hell yeah right into the garbage with that
@xdaniels13
@xdaniels13 Жыл бұрын
In next.js 13 app folder system, the Provider has to go in the main layout.tsx file, right? someone knows?
@zheil9152
@zheil9152 Жыл бұрын
I prefer RTK-Query since it also comes for free with RTK state management
@joshtriedcoding
@joshtriedcoding Жыл бұрын
fair enough
@bizmich_
@bizmich_ Жыл бұрын
can any one help i have problem with query params i cannot get them before rendering, I am using react-query by it cannot get them initial
@techlightdev
@techlightdev Жыл бұрын
So cool,
@waleedsharif618
@waleedsharif618 Жыл бұрын
Could you create app where is Nextjs in frontend and express in backend ? Tutorial
@mohitsharma-ep9iy
@mohitsharma-ep9iy 5 ай бұрын
in react query version 5 , it is written to support old browsers you have to transpile and polyfill yourself. Have you faced this type of issue where react query stopped working in old browsers ?
@thedevminer
@thedevminer Жыл бұрын
You missed explaining the `mutate`/`mutateAsync` functions that `useMutation` returns.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
ah thats right, good catch
@ninjagaskin
@ninjagaskin Жыл бұрын
Doesnt Nextjs handle the loading and error cases in the respective loading.tsx and error.tsx files? Is there still merit to using react query?
@ninjagaskin
@ninjagaskin Жыл бұрын
Great videos btw!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Thanks man. The loading.tsx and error.tsx is for server side errors and server side loading state. If you fetch data inside a server component, your loading.tsx will show up
@ninjagaskin
@ninjagaskin Жыл бұрын
Gotcha. Thank you for clearing that up. Would there be a purpose to run this react query in server side requests or is that not possible. Strictly for client side
@sinnis_879
@sinnis_879 Жыл бұрын
hey josh, can we use react query in Next js 13 with the revalidate and cache methods. or is it better to just use simple fetch api in nextjs 13 please reply
@censmart9486
@censmart9486 11 ай бұрын
At the top of your component write export const revalidate = 3600 // revalidate every hour, same as using using fetch API {next : { revalidate: 60} }
@timetosleep8055
@timetosleep8055 Жыл бұрын
Is the first load js when building the project always so huge when using react query? up to 350kb!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
no something is definitely not right in your project haha
@nada125love
@nada125love Жыл бұрын
Hi josh, can you please make a video about typescript and how can it be useful than JS for beginners with little tutorial
@nested9301
@nested9301 Жыл бұрын
Just google it it's 2023
@joshtriedcoding
@joshtriedcoding Жыл бұрын
thats a great suggestion
@keshawnsmith320
@keshawnsmith320 Жыл бұрын
Are you using windows 10 or 11?
@smotch7533
@smotch7533 Жыл бұрын
You should reference your recent videos on fetching...I though this was the same video
@joshtriedcoding
@joshtriedcoding Жыл бұрын
true, that might be a bit confusing. Its the more in-depth version as a lot of people asked for it
@SanderCokart
@SanderCokart Жыл бұрын
Axios does allow Generics so no need to do As casting
@indramal
@indramal 2 ай бұрын
why axios instead of fetch?
@guitarplayer1434
@guitarplayer1434 Жыл бұрын
where would I house videos and would I use react to fetch them for a video streaming site
@joshtriedcoding
@joshtriedcoding Жыл бұрын
upload them to AWS s3 or cloudinary (I prefer s3), then fetch them via a presigned url
@imkir4n
@imkir4n Жыл бұрын
HOW'S THE JOSH!!!
@ashish_prajapati_tr
@ashish_prajapati_tr Жыл бұрын
react-query is powerful
@joshtriedcoding
@joshtriedcoding Жыл бұрын
it is
@blossomdoom7609
@blossomdoom7609 Жыл бұрын
how do you mutate data in nextjs 13
@CapzTube
@CapzTube Жыл бұрын
OnSuccess and OnError for useQuery (not useMutation) will be being removed in React-Query 5 I think
@stefanplusplus917
@stefanplusplus917 Жыл бұрын
wait why?
@kamehameha38
@kamehameha38 Жыл бұрын
Why?
@_bigNPC_
@_bigNPC_ 11 ай бұрын
I’m a very fan of native apis and fetch API tbh, it not hard at all.
@fayez9939
@fayez9939 Жыл бұрын
useSWR is lightweight and enough for most of time.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
fair enough
@carlosalbertocabreraquirog8297
@carlosalbertocabreraquirog8297 Жыл бұрын
does react query work on nextjs?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
yeah
@rojka-_-
@rojka-_- 10 ай бұрын
awesome
@Zummota
@Zummota Жыл бұрын
6:04 how to do this editing trick?
@jimshtepa5423
@jimshtepa5423 Жыл бұрын
I didn't fully understand what query keys are for? what would not be possible in case query keys are not used? Please don't answer caching wouldnt be possible. I mean in practice how is behaviour of the fetching would be in case query key is not used?
@omarkraidie
@omarkraidie 11 ай бұрын
I cannot use useQuery in a server component?
@joshtriedcoding
@joshtriedcoding 11 ай бұрын
Hooks in general are client-only
@muneeburrehman547
@muneeburrehman547 Жыл бұрын
so you love react query ?
@ongkay250
@ongkay250 Жыл бұрын
i love SWR🤣
@muneeburrehman547
@muneeburrehman547 Жыл бұрын
@@ongkay250 lell
@joshtriedcoding
@joshtriedcoding Жыл бұрын
wouldnt call it love but I enjoy using it
@muneeburrehman547
@muneeburrehman547 Жыл бұрын
@@joshtriedcoding ohh then which library do you love personally?
@ongkay250
@ongkay250 Жыл бұрын
what about SWR ?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
as I said, they aim to accomplish a very similar thing
@sno-oze
@sno-oze 11 ай бұрын
onSuccess and onError is deprecated and will be removed in next major verions, interesting
@llmaboi
@llmaboi Жыл бұрын
The wording here is mis leading as React Query is not a data fetching client, axioms or fetch is. React Query is a state management tool with implementations for managing query responses.
@asimalqasmi7316
@asimalqasmi7316 Жыл бұрын
First 🎉
@joshtriedcoding
@joshtriedcoding Жыл бұрын
you are the man
@rudi-batubara
@rudi-batubara 10 ай бұрын
use-query + axios = (KB + KB) You should learn more about use-query and axios rather then business logic.😂
React Query Is (Still) Essential - My Favorite React Library
11:04
Theo - t3․gg
Рет қаралды 142 М.
How Did I Not Know This TypeScript Trick Earlier??!
9:11
Josh tried coding
Рет қаралды 203 М.
DELETE TOXICITY = 5 LEGENDARY STARR DROPS!
02:20
Brawl Stars
Рет қаралды 17 МЛН
Which one is the best? #katebrush #shorts
00:12
Kate Brush
Рет қаралды 22 МЛН
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 44 МЛН
This Package Saved My SaaS
5:46
Josh tried coding
Рет қаралды 39 М.
This Data Fetching Combo is OP
7:19
Josh tried coding
Рет қаралды 51 М.
Five Clever Hacks for React-Query and SWR
40:09
Jack Herrington
Рет қаралды 58 М.
Updates Like These Make Tailwind So Fun
8:00
Josh tried coding
Рет қаралды 71 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
You might not need useEffect() ...
21:45
Academind
Рет қаралды 150 М.
Why I avoid useEffect For API Calls and use React Query instead
17:45
Redux Toolkit Query vs React Query
22:12
Jack Herrington
Рет қаралды 103 М.
The Problem With UUIDs
6:36
Josh tried coding
Рет қаралды 68 М.
State Managers Are Making Your Code Worse In React
13:33
Web Dev Simplified
Рет қаралды 156 М.
Bluetooth Desert Eagle
0:27
ts blur
Рет қаралды 8 МЛН
One To Three USB Convert
0:42
Edit Zone 1.8M views
Рет қаралды 440 М.