Тёмный

Fetching Data in React - Complete Tutorial 

Cosden Solutions
Подписаться 104 тыс.
Просмотров 124 тыс.
50% 1

🚀 Project React → cosden.solutio...
📥 Import React (Newsletter) → cosden.solutio...
Join The Discord! → discord.cosden...
Source Code → github.com/cos...
In this video we talk about data fetching in React. This is a complete tutorial teaching you everything there is to know about how to fetch data in React. You'll learn about loading, handling error states, and even how to prevent race conditions using abort controllers. We'll use some hooks such as useState, useEffect, and useRef. We will use the fetch API from Node.js and we briefly mention React Query and how it can simplify things. Enjoy!

Опубликовано:

 

25 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 134   
@cosdensolutions
@cosdensolutions 6 месяцев назад
Hope you enjoyed the video! I also have a really cool and unique course that will teach you way more than this video. You'll learn how to build an actual complex project with React. It's called "Project React" and you can find it at cosden.solutions/project-react. Also, I have a free weekly newsletter called "Import React" with tutorials, news, and cool stuff about React! You can sign up at cosden.solutions/newsletter?s=ytc
@opyotusamuel
@opyotusamuel Месяц назад
😅😅😅😅😅😅
@amritghimire4791
@amritghimire4791 Месяц назад
😊
@craig1253
@craig1253 7 месяцев назад
Been stuck learning react for months and now I found this gem of a channel. Keep it up bro!
@НикитаБурлаков-у8ш
@НикитаБурлаков-у8ш 6 месяцев назад
I think u should also add some check statement for response.ok, because this is common case in handling responses from your own API, and u can receive response with status 400(some form validation error) or 500(some server internal error) and that's why its good practice to throw Error when !response.ok, btw, thanks for the video
@egy-90s
@egy-90s 9 месяцев назад
I like that you state the basics of fetching data instead of only (how to) , so thanks a lot for your help
@webdev-tom
@webdev-tom Год назад
Your videos are such a masterpiece 👍 I really hope your channel will grow very fast because you deserve it so much. Really good quality content 💯
@cosdensolutions
@cosdensolutions Год назад
thanks a lot! I hope so too!
@betull7
@betull7 2 месяца назад
this channel single-handedly saves my life
@Securitywasted
@Securitywasted Месяц назад
Best data fetching video in react i have ever seen. Expain every step in details Keep it up bro
@moviegift2492
@moviegift2492 3 месяца назад
I like your way of teaching and I am new for react, i came from backend zone so I am here for the next coding sessions to see how really manages my love of data. Thank you for your effort. u got one sub.
@KonstantinosKaminaris-xe8wt
@KonstantinosKaminaris-xe8wt 4 месяца назад
I aspire to one day be able to teach people like you do. This is really high quality teaching my friend. Respect.
@KojoJohnson
@KojoJohnson 2 месяца назад
I just subscribed live from Ghana West Africa, you teach very clean and straight fwd learned alot from you the least i can do is sub
@ooorayooonyoooo
@ooorayooonyoooo Год назад
bro you are always just straight to the point. Thanks Man!
@madhavvankina5201
@madhavvankina5201 11 месяцев назад
Your channel is gonna pop off. Your content is top-notch 💯💯
@iCeTainment
@iCeTainment Год назад
I just subscribed 🎉 Love your videos man! It’s helping me with my internship projects
@KarenDiaz-m6m
@KarenDiaz-m6m 10 месяцев назад
This video was extremely informative! Looking forward to watching more React content from your channel. Would be great if you could also make a best practices video for production code or even intermediate/advanced React videos
@erikreyes6093
@erikreyes6093 Год назад
wow very informative tutorial, there is so much to learn from you. I just hope you will keep creating vidoes that share your expertise in web development
@cosdensolutions
@cosdensolutions Год назад
will do!
@reihane2325
@reihane2325 8 месяцев назад
Thanks a lot for explain very clear. I saw lots of video in RU-vid, but your explain is so helpful for me as a junior react typescript developer. Bon courage!
@praulayar4805
@praulayar4805 9 месяцев назад
one of the best video on data fetching with vanilla data fetching
@shahnawazk
@shahnawazk 7 месяцев назад
One video to like and subscribe! Really helpful and informative. Thanks and keep it up.
@jellyfish1772
@jellyfish1772 10 месяцев назад
Just when i saw you were using typescript I knew this would be a great tutorial. great video❤
@rellamwahid6392
@rellamwahid6392 5 месяцев назад
thank you for the video, i think you should add a cleanup function in the useEffect hook to cancel any ongoing requests when the component unmounts or when page changes (talking about the abort ).
@lisalee7946
@lisalee7946 6 месяцев назад
Best instructor!! Thank you for such great content!!💯
@hilkiahlavinier
@hilkiahlavinier Год назад
Thanks for this great video. Will you consider doing a follow up video that discusses the pros/cons of the various (or most popular) React fetch methods/options (e.g. Axios et al) and suggest their usecases (when to use one over the other)?
@cosdensolutions
@cosdensolutions Год назад
Hmm not a bad idea tbh, will note it down!
@rishabhnegi9429
@rishabhnegi9429 8 месяцев назад
I am just obsessed with your videoes ... great work 😀
@djwooster
@djwooster 2 месяца назад
Love this explanation! May I suggest that you perhaps get a pop filter or somehow edit the audio (probably some quick AI solution) because every time you pronounce a 'p' sound it's loud af in my headphones lol but I LOVE the video!
@frankdearr2772
@frankdearr2772 20 дней назад
Great, thanks for all 👍
@goodness776
@goodness776 10 месяцев назад
Never seen a lean step by step explanation. You are indeed a masterpiece @webdev-tom💯
@tigranharutyunyan7674
@tigranharutyunyan7674 9 месяцев назад
Enthusiasm and knowledge! Thank you man
@incarnateTheGreat
@incarnateTheGreat 5 месяцев назад
Thanks for the Abort Controller solution!
@wallethe1614
@wallethe1614 Год назад
Awesome vid im learning alot, thank you and keep it going.
@cosdensolutions
@cosdensolutions Год назад
glad to hear it!
@2difficult2do
@2difficult2do Год назад
This is very interesting video, exactly what I looking for. Thank you. Like
@cosdensolutions
@cosdensolutions Год назад
glad you found it useful!
@TLTechbender
@TLTechbender 3 месяца назад
Thanks so much, you just helped me out big time!
@farhaannishtar786
@farhaannishtar786 6 месяцев назад
This guy is good. Thanks for making great content
@haiderjaafer8164
@haiderjaafer8164 Год назад
So useState is the Post a class previously you created so it here generic... Hope to clarify that... Thank
@cosdensolutions
@cosdensolutions Год назад
Yes, I created a type of Post, with id and title. There are more properties from the API but since we only use those, I just created that type!
@irfansaeedkhan7242
@irfansaeedkhan7242 Месяц назад
again with the ooint the more seniors I talked to they said don't use useEffect for API calls because first UI is rendered then useEffect runs, so its like render first then fetch data, but if you use rtk query it fetch first and then re render so UI comes with no glitch also it cache ur data, so useeffect sometimes causes too many renders issue if not done right, specially API calls is not recommended , in your react project course have you done API call same in useEffects or you have done them in differently ways as well ? i am planing to purchase it because the way you explain things is perfect
@jlogo80
@jlogo80 Год назад
Awesome stuff, thanks!
@tylerxx26
@tylerxx26 7 месяцев назад
Super stuff man. Please keep it up!🎉
@lynx7077
@lynx7077 6 месяцев назад
I was trying to start the core of your project and i was keep getting an error. I believe i re-wrote it like 4 times. And then i realized something i never learned before during my Bootcamp: you have everything with tsx lol. What i was trying to do, was to write everything in jsx. So i looked it up and apparently there is a "create react with typescript" 😵‍💫 and now it shows everything. Learning something new every day. Althought i am still a bit confused between tsx and jsx and their usage
@theMaroFlow
@theMaroFlow Месяц назад
Hi, this is amazing video i learn a lot, but wondering if in this code implementation need to add clean up function or this code is full correct and clean up not required.
@helenasdiaries515
@helenasdiaries515 8 месяцев назад
Thanks ! You are a great explainer
@Pareshbpatel
@Pareshbpatel Месяц назад
Data Fetching in React, so clearly explained. Thanks, Darius. {2024-08-27}
@vesa95
@vesa95 Год назад
Fire man! 🔥 I’ve wait for you to post!
@cosdensolutions
@cosdensolutions Год назад
Yes! More videos to come! I'm currently on vacation so I've posted a bit less
@kreten780
@kreten780 10 месяцев назад
For loading, I really like to use an object of properties like: const FETCH_STATUS = {IDLE: 'idle', LOADING: 'loading', ERROR: 'error', SUCCESS: 'success'}; In that way I have a little bit more control over what I display on different occasions.
@cosdensolutions
@cosdensolutions 10 месяцев назад
yep, that's another way to do it!
@MaxMov-sp8hr
@MaxMov-sp8hr 7 месяцев назад
One of the best! 👏
@hamzapaskingakhtar
@hamzapaskingakhtar 9 месяцев назад
This is pure gold
@INetreba
@INetreba 7 месяцев назад
very good explanation!
@MikeTheCook
@MikeTheCook 7 месяцев назад
Love it. You're the best.
@aswineepratihari7897
@aswineepratihari7897 8 месяцев назад
21:38 abort control
@BLUEGAMER26
@BLUEGAMER26 8 дней назад
You’re an angel, I was looking for this
@mafterr11
@mafterr11 Месяц назад
Outdated, since useEffect isnt really recomended for fetching anymore. Better ways to do it. Would love to see an updated video of this :)
@cosdensolutions
@cosdensolutions Месяц назад
actually posting that tomorrow :D. You're right, this is outdated, but still important if you're learning. You need to know and understand how to do this before moving on to RQ or server components
@enedigodswill
@enedigodswill 8 дней назад
Exactly I'm facing the same issue too, I'm still a beginner and I really need help with it
@ramirorenteria7333
@ramirorenteria7333 4 месяца назад
Awesome tutorial!
@erikreyes6093
@erikreyes6093 Год назад
Can you create a tutorial that shows the actual sql query that fetch records from database please. A plain sql query and sql that uses views and stored procedure please Thank you very much
@cosdensolutions
@cosdensolutions Год назад
probably not for a while, I am focusing on react at the moment!
@AkbarAli-bt7xi
@AkbarAli-bt7xi 7 дней назад
thanks sir
@Lidkovsky
@Lidkovsky 10 месяцев назад
golden content.
@TausifShekh-j5x
@TausifShekh-j5x Год назад
please make videos on doing project. your channel is growing since last time i commented doing great keep it up i am your subscriber
@cosdensolutions
@cosdensolutions Год назад
How about livestreaming building an entire app from scratch, while also making it open source so anybody can contribute no matter the skill level? It'll be a great way to learn and build something real! And also, no worries, all videos will be available even after the live stream!
@TausifShekh-j5x
@TausifShekh-j5x Год назад
@@cosdensolutions yes thats good idea
@rajnishkushx
@rajnishkushx 8 месяцев назад
Luv bro, from Bharat ❤
@Oshione-w9c
@Oshione-w9c 10 месяцев назад
excellent video very imformative guy
@dardaniaa0546
@dardaniaa0546 7 месяцев назад
React Query makes this super easy
@cosdensolutions
@cosdensolutions 7 месяцев назад
it does
@harag9
@harag9 11 месяцев назад
Great video. The main different I do is with the abortController, I always put that in the cleanup return, which is what I've seen in several other videos on the same topic, it's interesting to see you doing it differently, both ways look like it will work just as well though. As for React Query you mentioned, do you plan on doing a tutorial on that?
@cosdensolutions
@cosdensolutions 11 месяцев назад
Yeah that's another way to do it! And the RQ video has been up for a while already ☺️
@harag9
@harag9 11 месяцев назад
@@cosdensolutions Ahh cool, still working my way through the videos. :) Really enjoying them .
@MuhammadWaqas-eb1uu
@MuhammadWaqas-eb1uu 6 месяцев назад
Can I use hook useloader as async fucntion to fetch api data. That is optimize way and performance application increase.
@haroonkhan-dy9bt
@haroonkhan-dy9bt Год назад
Hey great tutorials will do a context api tutorial with fetching data and adding a cart functionality etc?
@cosdensolutions
@cosdensolutions Год назад
Haven't gotten around to doing tutorials of actual features but yes, I will do! However I have already a tutorial on useContext 😁
@Anilsinghchd
@Anilsinghchd 4 месяца назад
Great content
@memeMerge
@memeMerge Год назад
I really liked it 👍👍
@thisstory
@thisstory 7 месяцев назад
Love your videos
@joshuac9142
@joshuac9142 4 месяца назад
Perfect!
@apoorvgupta9680
@apoorvgupta9680 Месяц назад
we can also return request.abort
@EzekielOladejo-f1u
@EzekielOladejo-f1u Год назад
What theme is this? Does anyone know? Thank you in advance 🙏🙏
@cosdensolutions
@cosdensolutions Год назад
Material theme darker
@EzekielOladejo-f1u
@EzekielOladejo-f1u Год назад
@@cosdensolutions Thank you!!
@piotrszczesniak
@piotrszczesniak 7 месяцев назад
Hey Cosden! Thanks for the video. I never considered, or even never heard of, cancelling the racing condition. What I would normally do it is to disable the button that fires another call when the isLoading is true - it does the job 🚀. What do you think about my solution?
@cosdensolutions
@cosdensolutions 7 месяцев назад
It would work, but then you're blocking the UI waiting for a response. What if the user changes their mind before the request returns? It's easier to let them change their mind and just cancel the pending request
@piotrszczesniak
@piotrszczesniak 7 месяцев назад
@@cosdensolutions I agree with you. Actually, this is the first time I heard about the abortController(). I will keep this video as a reference when I develop sth that would need the abortController(). In my case, using isLoading to disable the UI for a second is a good enough option :)
@abhinasregmi9742
@abhinasregmi9742 7 месяцев назад
I was wondering if we could add signal aborting in cleanup for useEffect instead at the top 🤔🤔 Will this work??
@cosdensolutions
@cosdensolutions 7 месяцев назад
yes it would, it's actually better!
@Riflijones01
@Riflijones01 6 месяцев назад
You WILL want to watch another video on Fetching Data. Watch as many as you can because that will show you that there are other ways of doing things
@shashwatgupta2184
@shashwatgupta2184 5 месяцев назад
Can you provide few links looks like you already seen some different ways
@haiderjaafer8164
@haiderjaafer8164 Год назад
Really great keep going forward... But learning react in js not in type script
@cosdensolutions
@cosdensolutions Год назад
that's fine! Just ignore the types then! But it would be useful to just be familiar with it, so that when you eventually do go to typescript (you should), you'll be more familiar!
@aggranular
@aggranular 3 месяца назад
If you don’t care about type of error you should use unknown, not any
@garikmelqonyan6011
@garikmelqonyan6011 7 месяцев назад
Good job!
@abdalghanialbiek8999
@abdalghanialbiek8999 8 месяцев назад
I wish to play this sound when Eren meet Anni in all timelines
@hameeeed5992
@hameeeed5992 3 месяца назад
Thanks
@JonathanKila
@JonathanKila 7 месяцев назад
Any resource on data fetching and caching? Like why should I use React Query, SWR?
@cosdensolutions
@cosdensolutions 7 месяцев назад
I have a video on RQ as well
@DrivingScape
@DrivingScape 21 час назад
Nice vid, thanks
@richardleungwoogabriel9317
@richardleungwoogabriel9317 11 месяцев назад
Great video! But I’m trying to get in your discord channel but I need an invite link. The link in the description doesn’t work for me
@cosdensolutions
@cosdensolutions 11 месяцев назад
it should work, or just manually go to discord.cosdensolutions.io
@faisalhussain7008
@faisalhussain7008 7 месяцев назад
What if we abort the request inside the cleanup function?
@cosdensolutions
@cosdensolutions 7 месяцев назад
Yeah that's better!
@MarkDavid-so9up
@MarkDavid-so9up 8 месяцев назад
Which is better? const fn = async() => {} fn() Or (async(){})()
@kkatsavaros
@kkatsavaros 7 месяцев назад
Thank you, but why i take back two responses,? These responses are the same.
@cosdensolutions
@cosdensolutions 7 месяцев назад
Maybe because you're in strict mode and React fires all useEffects twice
@kkatsavaros
@kkatsavaros 7 месяцев назад
Yes, exactly. Thank you very much.
@maryambibi9687
@maryambibi9687 9 месяцев назад
Can you make one video in react life cycles ?
@СандугашАхметжанова-п5ф
please make a video about typescript, this new syntax sometimes shocks me
@cosdensolutions
@cosdensolutions Год назад
Will do!
@capt_vj
@capt_vj 7 месяцев назад
awesome !
@sehlanarslan1792
@sehlanarslan1792 7 месяцев назад
@aggranular
@aggranular 3 месяца назад
I like your video but got a big fat 👎 for as Posts[] antipattern. Should have at least mentioned that in real application you should validate the response a type safe schema library
@bidsouravbest
@bidsouravbest 7 месяцев назад
Pls make your codes on JS. PLS
@cosdensolutions
@cosdensolutions 7 месяцев назад
just ignore the types
@AyushManShrestha
@AyushManShrestha 9 месяцев назад
TypeError: posts.map is not a function {isLoading && Loading...} {!isLoading && ( {posts.map((post) => { return {post.title}; })} )}
@marcrichet2626
@marcrichet2626 11 месяцев назад
Bonsoir, What's your vscode theme please? :)
@sumeettiwari4060
@sumeettiwari4060 10 месяцев назад
Material theme
@ABDULLAHKHALID-ix6db
@ABDULLAHKHALID-ix6db 8 месяцев назад
@brandonhopkins3438
@brandonhopkins3438 11 месяцев назад
Big shame it's written in typescript. Still, transferred it to js and this was a great tutorial. Liked. Subscribed.
@cosdensolutions
@cosdensolutions 11 месяцев назад
No problem if you use JS, but my advice is to start thinking about TS because it will probably become the standard eventually!
@harag9
@harag9 11 месяцев назад
As Darius has said, I too would recommend picking up TS and learning that, it really does help.
@josepdevillaret
@josepdevillaret 4 месяца назад
Can i contact you personally? I've got a project I'd like to get some React expertise in order to set a cart onto Framer (via React)
@josepdevillaret
@josepdevillaret 4 месяца назад
by connecting shopify backend onto framer frontend (via embeded code)
@choppdick433
@choppdick433 6 месяцев назад
Hi, I am an Angular developor is learning react. I love the abortControllorRef best practice you used handle the api paging part that let the later fetch to cancel the conducting fetch, which works same as the higher order mapping operater switchMap() in Angular Rxjs. I got one question here: there is another higher order mapping operater is concatMap() which is used to make sure that the later request always start after the previous request complete. so In your case it would be like: you increase the page to 2 (that will try to fatch the page 2 data) when the app is still loading the page 1, result will be: "the page 2 request will always start after the page 1 request complete" this can be useful for the case that the later request is depended on the previous reuqest. is there any way to implement that in React?
@jay-kv6wn
@jay-kv6wn Год назад
Great content
Далее