Fetching Data in React - Complete Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2024

ความคิดเห็น • 138

  • @cosdensolutions
    @cosdensolutions  9 หลายเดือนก่อน +8

    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

  • @craig1253
    @craig1253 10 หลายเดือนก่อน +17

    Been stuck learning react for months and now I found this gem of a channel. Keep it up bro!

  • @shya666
    @shya666 28 วันที่ผ่านมา +1

    Talking about race conditions for a language that is not even multi-threaded is wild. But a very well-made tutorial. Thank you.

  • @mohamedsaed1558
    @mohamedsaed1558 หลายเดือนก่อน

    in my mind I was thinking that if I find a teacher teach me every piece of code, then I find you, you make code incredible easy, and completely for free, only teacher like you can only create channel you , I wish for you all the best

  • @Securitywasted
    @Securitywasted 4 หลายเดือนก่อน +2

    Best data fetching video in react i have ever seen. Expain every step in details
    Keep it up bro

  • @НикитаБурлаков-у8ш
    @НикитаБурлаков-у8ш 9 หลายเดือนก่อน +16

    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

  • @betull7
    @betull7 5 หลายเดือนก่อน +1

    this channel single-handedly saves my life

  • @KonstantinosKaminaris-xe8wt
    @KonstantinosKaminaris-xe8wt 7 หลายเดือนก่อน +1

    I aspire to one day be able to teach people like you do. This is really high quality teaching my friend. Respect.

  • @webdev-tom
    @webdev-tom ปีที่แล้ว +10

    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 💯

  • @madhavvankina5201
    @madhavvankina5201 ปีที่แล้ว +2

    Your channel is gonna pop off. Your content is top-notch 💯💯

  • @moviegift2492
    @moviegift2492 6 หลายเดือนก่อน

    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.

  • @praulayar4805
    @praulayar4805 ปีที่แล้ว

    one of the best video on data fetching with vanilla data fetching

  • @reihane2325
    @reihane2325 11 หลายเดือนก่อน

    Thanks a lot for explain very clear. I saw lots of video in TH-cam, but your explain is so helpful for me as a junior react typescript developer. Bon courage!

  • @erikreyes6093
    @erikreyes6093 ปีที่แล้ว +1

    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

  • @lisalee7946
    @lisalee7946 9 หลายเดือนก่อน

    Best instructor!! Thank you for such great content!!💯

  • @KojoJohnson
    @KojoJohnson 5 หลายเดือนก่อน

    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

  • @shahnawazk
    @shahnawazk 10 หลายเดือนก่อน +1

    One video to like and subscribe! Really helpful and informative. Thanks and keep it up.

  • @iCeTainment
    @iCeTainment ปีที่แล้ว +3

    I just subscribed 🎉
    Love your videos man! It’s helping me with my internship projects

  • @jellyfish1772
    @jellyfish1772 ปีที่แล้ว

    Just when i saw you were using typescript I knew this would be a great tutorial. great video❤

  • @rishabhnegi9429
    @rishabhnegi9429 11 หลายเดือนก่อน

    I am just obsessed with your videoes ... great work 😀

  • @KarenDiaz-m6m
    @KarenDiaz-m6m ปีที่แล้ว +2

    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

  • @ashsad521
    @ashsad521 2 หลายเดือนก่อน

    Thanks very much for that great video, very clear and organized

  • @farhaannishtar786
    @farhaannishtar786 9 หลายเดือนก่อน

    This guy is good. Thanks for making great content

  • @tigranharutyunyan7674
    @tigranharutyunyan7674 ปีที่แล้ว

    Enthusiasm and knowledge! Thank you man

  • @goodness776
    @goodness776 ปีที่แล้ว

    Never seen a lean step by step explanation. You are indeed a masterpiece @webdev-tom💯

  • @ooorayooonyoooo
    @ooorayooonyoooo ปีที่แล้ว +3

    bro you are always just straight to the point. Thanks Man!

  • @tylerxx26
    @tylerxx26 10 หลายเดือนก่อน

    Super stuff man. Please keep it up!🎉

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

  • @incarnateTheGreat
    @incarnateTheGreat 8 หลายเดือนก่อน

    Thanks for the Abort Controller solution!

  • @wallethe1614
    @wallethe1614 ปีที่แล้ว +1

    Awesome vid im learning alot, thank you and keep it going.

  • @jlogo80
    @jlogo80 ปีที่แล้ว +1

    Awesome stuff, thanks!

  • @2difficult2do
    @2difficult2do ปีที่แล้ว +1

    This is very interesting video, exactly what I looking for. Thank you. Like

  • @TLTechbender
    @TLTechbender 6 หลายเดือนก่อน

    Thanks so much, you just helped me out big time!

  • @MaxMov-sp8hr
    @MaxMov-sp8hr 10 หลายเดือนก่อน

    One of the best! 👏

  • @frankdearr2772
    @frankdearr2772 3 หลายเดือนก่อน

    Great, thanks for all 👍

  • @ramirorenteria7333
    @ramirorenteria7333 7 หลายเดือนก่อน

    Awesome tutorial!

  • @rellamwahid6392
    @rellamwahid6392 8 หลายเดือนก่อน

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

  • @hamzapaskingakhtar
    @hamzapaskingakhtar ปีที่แล้ว

    This is pure gold

  • @MikeTheCook
    @MikeTheCook 10 หลายเดือนก่อน

    Love it. You're the best.

  • @Pareshbpatel
    @Pareshbpatel 4 หลายเดือนก่อน

    Data Fetching in React, so clearly explained. Thanks, Darius.
    {2024-08-27}

  • @INetreba
    @INetreba 10 หลายเดือนก่อน

    very good explanation!

  • @djwooster
    @djwooster 5 หลายเดือนก่อน

    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!

  • @xK1NGxSDx
    @xK1NGxSDx 8 วันที่ผ่านมา

    God bless your soul I was almost cooked at work

  • @helenasdiaries515
    @helenasdiaries515 11 หลายเดือนก่อน

    Thanks ! You are a great explainer

  • @DrivingScape
    @DrivingScape 3 หลายเดือนก่อน

    Nice vid, thanks

  • @rajnishkushx
    @rajnishkushx 11 หลายเดือนก่อน

    Luv bro, from Bharat ❤

  • @kreten780
    @kreten780 ปีที่แล้ว

    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.

  • @memeMerge
    @memeMerge ปีที่แล้ว

    I really liked it 👍👍

  • @lilynn7777
    @lilynn7777 9 หลายเดือนก่อน

    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

  • @hilkiahlavinier
    @hilkiahlavinier ปีที่แล้ว +3

    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  ปีที่แล้ว +1

      Hmm not a bad idea tbh, will note it down!

  • @Lidkovsky
    @Lidkovsky ปีที่แล้ว

    golden content.

  • @thisstory
    @thisstory 10 หลายเดือนก่อน

    Love your videos

  • @Oshione-w9c
    @Oshione-w9c ปีที่แล้ว

    excellent video very imformative guy

  • @Riflijones01
    @Riflijones01 9 หลายเดือนก่อน +1

    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 8 หลายเดือนก่อน

      Can you provide few links looks like you already seen some different ways

  • @irfansaeedkhan7242
    @irfansaeedkhan7242 4 หลายเดือนก่อน

    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

  • @haiderjaafer8164
    @haiderjaafer8164 ปีที่แล้ว +2

    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!

  • @garikmelqonyan6011
    @garikmelqonyan6011 10 หลายเดือนก่อน

    Good job!

  • @jay-kv6wn
    @jay-kv6wn ปีที่แล้ว

    Great 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

  • @dardaniaa0546
    @dardaniaa0546 10 หลายเดือนก่อน

    React Query makes this super easy

  • @theMaroFlow
    @theMaroFlow 4 หลายเดือนก่อน

    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.

  • @Akbarali0011
    @Akbarali0011 3 หลายเดือนก่อน

    thanks sir

  • @aswineepratihari7897
    @aswineepratihari7897 11 หลายเดือนก่อน +1

    21:38 abort control

    • @BLUEGAMER26
      @BLUEGAMER26 3 หลายเดือนก่อน

      You’re an angel, I was looking for this

  • @joshuac9142
    @joshuac9142 7 หลายเดือนก่อน

    Perfect!

  • @mafterr11
    @mafterr11 4 หลายเดือนก่อน

    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  4 หลายเดือนก่อน

      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 3 หลายเดือนก่อน

      Exactly I'm facing the same issue too, I'm still a beginner and I really need help with it

  • @haroonkhan-dy9bt
    @haroonkhan-dy9bt ปีที่แล้ว +1

    Hey great tutorials will do a context api tutorial with fetching data and adding a cart functionality etc?

    • @cosdensolutions
      @cosdensolutions  ปีที่แล้ว +1

      Haven't gotten around to doing tutorials of actual features but yes, I will do! However I have already a tutorial on useContext 😁

  • @EzekielOladejo-f1u
    @EzekielOladejo-f1u ปีที่แล้ว +1

    What theme is this? Does anyone know?
    Thank you in advance 🙏🙏

  • @abhinasregmi9742
    @abhinasregmi9742 10 หลายเดือนก่อน

    I was wondering if we could add signal aborting in cleanup for useEffect instead at the top 🤔🤔 Will this work??

    • @cosdensolutions
      @cosdensolutions  10 หลายเดือนก่อน +1

      yes it would, it's actually better!

  • @harag9
    @harag9 ปีที่แล้ว

    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  ปีที่แล้ว +1

      Yeah that's another way to do it! And the RQ video has been up for a while already ☺️

    • @harag9
      @harag9 ปีที่แล้ว

      @@cosdensolutions Ahh cool, still working my way through the videos. :) Really enjoying them .

  • @hameeeed5992
    @hameeeed5992 6 หลายเดือนก่อน

    Thanks

  • @piotrszczesniak
    @piotrszczesniak 10 หลายเดือนก่อน

    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  10 หลายเดือนก่อน +1

      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 10 หลายเดือนก่อน

      @@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 :)

  • @capt_vj
    @capt_vj 10 หลายเดือนก่อน

    awesome
    !

  • @erikreyes6093
    @erikreyes6093 ปีที่แล้ว +2

    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  ปีที่แล้ว +1

      probably not for a while, I am focusing on react at the moment!

  • @richardleungwoogabriel9317
    @richardleungwoogabriel9317 ปีที่แล้ว

    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  ปีที่แล้ว

      it should work, or just manually go to discord.cosdensolutions.io

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

  • @MuhammadWaqas-eb1uu
    @MuhammadWaqas-eb1uu 9 หลายเดือนก่อน

    Can I use hook useloader as async fucntion to fetch api data. That is optimize way and performance application increase.

  • @JonathanKila
    @JonathanKila 10 หลายเดือนก่อน

    Any resource on data fetching and caching? Like why should I use React Query, SWR?

    • @cosdensolutions
      @cosdensolutions  10 หลายเดือนก่อน +1

      I have a video on RQ as well

  • @aggranular
    @aggranular 6 หลายเดือนก่อน

    If you don’t care about type of error you should use unknown, not any

  • @СандугашАхметжанова-п5ф
    @СандугашАхметжанова-п5ф ปีที่แล้ว

    please make a video about typescript, this new syntax sometimes shocks me

  • @faisalhussain7008
    @faisalhussain7008 10 หลายเดือนก่อน

    What if we abort the request inside the cleanup function?

  • @abdalghanialbiek8999
    @abdalghanialbiek8999 ปีที่แล้ว

    I wish to play this sound when Eren meet Anni in all timelines

  • @maryambibi9687
    @maryambibi9687 ปีที่แล้ว

    Can you make one video in react life cycles ?

  • @kkatsavaros
    @kkatsavaros 10 หลายเดือนก่อน

    Thank you, but why i take back two responses,? These responses are the same.

    • @cosdensolutions
      @cosdensolutions  10 หลายเดือนก่อน

      Maybe because you're in strict mode and React fires all useEffects twice

    • @kkatsavaros
      @kkatsavaros 10 หลายเดือนก่อน

      Yes, exactly. Thank you very much.

  • @apoorvgupta9680
    @apoorvgupta9680 4 หลายเดือนก่อน

    we can also return request.abort

  • @relatable_content5
    @relatable_content5 11 หลายเดือนก่อน

    Which is better?
    const fn = async() => {}
    fn()
    Or
    (async(){})()

  • @sehlanarslan1792
    @sehlanarslan1792 10 หลายเดือนก่อน

  • @marcrichet2626
    @marcrichet2626 ปีที่แล้ว

    Bonsoir, What's your vscode theme please? :)

  • @aggranular
    @aggranular 6 หลายเดือนก่อน

    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

  • @AyushManShrestha
    @AyushManShrestha ปีที่แล้ว

    TypeError: posts.map is not a function
    {isLoading && Loading...}
    {!isLoading && (
    {posts.map((post) => {
    return {post.title};
    })}
    )}

  • @bidsouravbest
    @bidsouravbest 10 หลายเดือนก่อน

    Pls make your codes on JS. PLS

  • @brandonhopkins3438
    @brandonhopkins3438 ปีที่แล้ว +3

    Big shame it's written in typescript. Still, transferred it to js and this was a great tutorial. Liked. Subscribed.

    • @cosdensolutions
      @cosdensolutions  ปีที่แล้ว +4

      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 ปีที่แล้ว

      As Darius has said, I too would recommend picking up TS and learning that, it really does help.

  • @ABDULLAHKHALID-ix6db
    @ABDULLAHKHALID-ix6db 11 หลายเดือนก่อน

  • @rodriruiz7654
    @rodriruiz7654 2 หลายเดือนก่อน

    Stop trying to make fetch happen!!

  • @josepdevillaret
    @josepdevillaret 7 หลายเดือนก่อน

    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 7 หลายเดือนก่อน

      by connecting shopify backend onto framer frontend (via embeded code)

  • @Anilsinghchd
    @Anilsinghchd 7 หลายเดือนก่อน

    Great content