Infinite Scrolling With React - Tutorial

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

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

  • @shivaskanthan6144
    @shivaskanthan6144 3 หลายเดือนก่อน +2

    4 years later and this still works like a gem, Kudos to you!

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

    Gotta say...this is probably the best, most straightforward tutorial I've ever seen!

    • @Mike37373
      @Mike37373 4 ปีที่แล้ว

      why is openlibrary.org/search.json empty?

    • @jefffideler8046
      @jefffideler8046 4 ปีที่แล้ว

      @@Mike37373 perhaps it needs params i.e.
      axios({
      method: 'GET',
      url: url,
      params: { q: query, page: pageNumber },
      cancelToken: new axios.CancelToken(c => cancel = c)
      }).then

    • @serhendiefendi
      @serhendiefendi 4 ปีที่แล้ว

      i agree

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

    Hey!, just a simple tip that i use, is when you want to know if an array have elements (means its length is greather than 0), you only have to put array.length instead of array.length > 0, because if array.length is 0, 0 means false, and if is not 0 so is true, sorry if my english is bad.

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

      No need to apologize for your English. it was understandable.

    • @nishantmogha7679
      @nishantmogha7679 3 ปีที่แล้ว

      Or you can just use the array, [] is falsy.

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

      @@nishantmogha7679 array [] and {} are truthy brah

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

      Also to make sure the app won't crash when array is null use optional chaining like myArr?.length

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

      You can do that, but sometimes clearly code better than clever code

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

    when i click this video, i only expect to know how to implement infinity scroll. But after 25 minutes i have learned way more than that, like custom hook. Thank you so much

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

    awesome video. infinite scrolling starts at 17:50

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

    Man I have watched literally thousands of paid courses, but no course matches the level of explanation that this guy provides. Simply Amazing. Hats off!

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

    That useCallback() behavior with useRef() that confused me, now I got it. Thank you Kyle, this is the best explanation about infinite scrolling with react 😍😍

  • @rajapavithraselvaraj5937
    @rajapavithraselvaraj5937 2 ปีที่แล้ว

    I really have to say.. this was the best, clear, very staright forward tutorial. AWESOME

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

    Amazing tutorial, as special the approach to trigger the axios function via IntersectionObserver instead of div.scrollHeight.

  • @rizqyhbb
    @rizqyhbb 2 ปีที่แล้ว

    just from this video I have learned so many things, mainly the useRef and useCallback. thankyou

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

    I think this deserves a clarification - it's not just useCallback that can be assigned to an element's ref. Any function can be passed there, you just need to be very careful if the function updates state, since it can cause infinite re-renders.
    Therefore, in this scenario, Kyle is right to use the useCallback hook, as the function he's using calls setPageNumber.
    Let's say he used a plain function: the function he's using sets the state at some point, which re-renders the component. When the component gets re-rendered, the function gets reinstantiated. Since it's passed to an element's ref, the element gets re-rendered, which calls the function again. The function changes the state, causing the component to re-render... and we have ourselves an infinite loop.

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

      Wonderful explanation!!

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

      this literally just happened in class a few minutes ago in this example our TA was showing us...thank you now I understand why

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

      Why can't we just create an reference using useRef and pass it to the component. Then Handel the intersection observer without a function.

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

      Great explanation

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

      Thanks for explaining that, this is the only section in the video that I needed more explanation on

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

    Kyle, you are great. Never found a tutor explaining such complex topics so easily. 😊

  • @supreechajaijumpa4656
    @supreechajaijumpa4656 2 ปีที่แล้ว

    I'm tried to use infinite scrolling library but it not looking good.
    Your video had save my life it working great and smooth, Thanks

  • @봄여율-u9f
    @봄여율-u9f 3 ปีที่แล้ว

    This react lecture is AMAZING... Thanks from Korea.

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

    Great to see a video that includes some of the more advanced React features. I'll definitely need to watch this again, which is a feature of the best code run through videos.

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

    thanks!! used your pagination api with this, tweaked it a little as i'm using sequelize and it works great.

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

    Awesome tutorial man. Straight to the point and well explained. Got an infinite scroll up and working in my application no problem after watching this. Subscribed!

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

    Thank you so much for this tutorial, it literally helped me pass in a interview test 👏

  • @acedecastro83
    @acedecastro83 5 ปีที่แล้ว +12

    Learned a lot from this. Thank you so much Kyle 🙏🏼

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

    Thank you so much! I was struggling with window object so long and finally your video helped me!

    • @frontendHacks
      @frontendHacks 2 ปีที่แล้ว

      th-cam.com/video/c0nKjMnDfG4/w-d-xo.html&ab_channel=Front-EndHacks
      Watch Infinite Scroll Video here in Hindi

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

    This is a great tutorial, straight to the point and clear. Thank you, Kyle!

  • @romihasan380
    @romihasan380 3 ปีที่แล้ว

    you've a better solution than using scroll position broo, good job!!

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

    I. You are awesome. This video is amazing. You just went straight to the point and your language was very clear. Thanks for sharing this content.

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

    Just used this at work. Thank you Kyle!

  • @LinkSake
    @LinkSake 5 ปีที่แล้ว +6

    Amazing! Thank you very much, I thought it would be harder to make something like this.
    Also THANKS because I finally got how to make a custom hook, I was having some struggles to get it.

  • @mohammadaldibes6879
    @mohammadaldibes6879 2 ปีที่แล้ว

    The best tutorial I've ever seen

  • @nalladileepreddy1436
    @nalladileepreddy1436 3 ปีที่แล้ว

    Never saw any better explaination than this, thank you ..

  • @parasarora5869
    @parasarora5869 5 ปีที่แล้ว

    its totally amazing. i dont know about intersection observer so was a bit confused there but the video was mind blowing. Thanks for explaining the idea behind the infinite scroll

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

      Intersection Observer is a bit complex, but it makes doing things like infinite scrolling so much easier.

    • @parasarora5869
      @parasarora5869 5 ปีที่แล้ว

      @@WebDevSimplified yes.. absolutely correct

  • @АлинаКуракина-в9у
    @АлинаКуракина-в9у 10 หลายเดือนก่อน

    Thank you for making such an understandable and useful lessons! You're really great🙏💛

  • @ismoilshokirov
    @ismoilshokirov 3 ปีที่แล้ว

    Really good approach, dude your video helped me a lot to finish my project at work, Thank you so much

  • @MaxAigner
    @MaxAigner 2 ปีที่แล้ว

    I am really impressed by this tutorial, it helped me a lot in my current react project, thank you!

  • @NikhilAdiga
    @NikhilAdiga 3 ปีที่แล้ว

    Thank you so much! None of the other solutions worked for me except this!

  • @usamatahir6413
    @usamatahir6413 3 ปีที่แล้ว

    Thanks for the tutorial. This is probably the best, most straightforward tutorial

  • @RizaHariati
    @RizaHariati 3 ปีที่แล้ว

    The intersectionObserver is awesome!! so much more practical!

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

    Thank you for this tutorial! I got something similar workign, I just wanted the "isVisible" for one of my elements to show up.
    I think this video is a little too long, and getting the custom hook created is a little bit of a side job for getting infinite scrolling, and I would have preferred just getting the "isVisible" working, and then going from there.
    That being said, thanks for the info, your tutorials are always at a good pace, and I like that you've included the source code!

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

    Just a side note, you can also use Debounce Component to have delay when the user stops typing. Anyway, Great job! thanks for this!

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

      Very true. For this small use case it isn't really a big deal, but in a larger application this could save a lot of performance. Thanks for the tip.

    • @ManishKarki
      @ManishKarki 5 ปีที่แล้ว

      @@WebDevSimplified can you point me to some resource for this"debounce"? Thanks

    • @brindch8372
      @brindch8372 5 ปีที่แล้ว

      @@ManishKarki you can search for react-debounce-input

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

      @@ManishKarki Just do a Google search for React debounce. Essentially all it is, is delaying the axios request.

  • @viratkohli-jr6md
    @viratkohli-jr6md 3 ปีที่แล้ว

    Cool . Got my all doubt cleared. Nice work

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

    Your tutorials are incredible! It's so much great information in such a concise presentation.

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

    Awesome tutorial mate! I suggest including "Custom React Hooks" in your title. I was actually pleasantly surprised that this tutorial was going to include custom hooks. If I had saw that in the title, I would have clicked on it way earlier since React Hooks is the hot thing that everyone should be learning now. Furthermore, now that I've saved this to my React playlist, I still won't know that it includes custom hooks when I scan through all the video titles.

  • @Nil-js4bf
    @Nil-js4bf 2 ปีที่แล้ว

    Didn't realize so little code was required for this. I'm too used to using libraries and I'm not aware of what Web APIs there are. Going to put an effort to learning more of these things and getting comfortable with web APIs like Intersection observers and setting it all up with refs and callbacks

  • @itsatimemachine
    @itsatimemachine 3 ปีที่แล้ว

    your videos are awesome-- thank you!
    also, happy new year

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

    There is one serious situation custom hooks can land into is when the arguments change, the useEffect inside hook is not called synchoronously, in fact it is called asynchronously whenever React wants, therefore, the very first render after the change of the arguments, hook will still return the stale data (in this case the books because of useState). I land into this issue when I was creating my useLocalStorage which takes a key. And when I change the key it still returns data for the old key. This scenario is well taken care by useSWR hook, the moment the API URL changes the data returned is different. Can you make a video regarding these advanced patterns in REACT sometime?. That would be wonderful!

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

    A very great tutorial man.

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

    5:24 - use https if you have problems

  • @faris.abuali
    @faris.abuali ปีที่แล้ว

    Great explanation! Thanks Kyle!

  • @ankitmehrotra8519
    @ankitmehrotra8519 4 ปีที่แล้ว

    Thanks a lot Kyle. All of your videos are top notch..

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

    This tutorial is amazing! Thank you very much for making it simpler!

  • @AbhishekBijalwanGaz
    @AbhishekBijalwanGaz 4 ปีที่แล้ว

    1000 likes from my side, Brother.

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

    Using the ref on the children will force them to re-render when they're not the last item in the array, so maybe is better to use a the ref on a footer or something to observe the IntersectionObserver.
    And use useEffect to have the same functionality.

  • @kat802
    @kat802 3 ปีที่แล้ว

    thanks dude, u save my job. button like for u

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

    Very clever implementation!

  • @mcy93w
    @mcy93w 3 ปีที่แล้ว

    24k pure gold. Thank you so much!

  • @mayurborse1745
    @mayurborse1745 4 ปีที่แล้ว

    Awesome. Just what I was looking for. I used it in photo grid and full screen view in my app. Thanks

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

    Nice video, worked like a charm

  • @anshshrivastava9107
    @anshshrivastava9107 3 ปีที่แล้ว

    Thanks for this man, exactly what I was looking for, now I can create what I wanted. THANKSSSSSSSSSSSSSS

  • @razzsawhoney2818
    @razzsawhoney2818 4 ปีที่แล้ว

    Thanks man. A much needed tutorial for me...

  • @jhmesseroux
    @jhmesseroux 2 ปีที่แล้ว

    incredible bro i appreciate this🙌 kind of content

  • @amitpareek8905
    @amitpareek8905 4 ปีที่แล้ว

    Amazing video. You have made a complex thing look so easy. Keep up the great work!!
    Thank you!

    • @frontendHacks
      @frontendHacks 2 ปีที่แล้ว

      th-cam.com/video/c0nKjMnDfG4/w-d-xo.html&ab_channel=Front-EndHacks
      Watch Infinite Scroll Video here in Hindi

  • @chexter-wang
    @chexter-wang 3 ปีที่แล้ว

    This is so easy to use and does help a lot! Thank you for the video!

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

    Great Tutorial... Helped a lot

  • @DieterWiesflecker
    @DieterWiesflecker 3 ปีที่แล้ว

    Very very straightforward, keep the good work and thanks!

  • @soultouchingsongs
    @soultouchingsongs 4 ปีที่แล้ว

    Thanks a lot for the video🙏. Finally understood infinite scrolling.👍

  • @KarahannAe
    @KarahannAe 3 ปีที่แล้ว

    Thank you for this amazing video! My project was a little different but I managed to make it work in a short amount of time.

    • @frontendHacks
      @frontendHacks 2 ปีที่แล้ว

      th-cam.com/video/c0nKjMnDfG4/w-d-xo.html&ab_channel=Front-EndHacks
      Watch Infinite Scroll Video here in Hindi

  • @niyongaboeric
    @niyongaboeric 4 ปีที่แล้ว

    Hi Kyle, thank you for sharing the video. 17: 05 to 17: 46 min saved me. I never used two userEffect before, one to clean the state another to fetch data until I watched your video.
    I am implementing Cursor relay pagination. I had an issue about clearing old data. Whenever react-route changes I could get old data and new data repeatedly. I 've fixed the issue after 2 days struggling with your help.
    God bless you brother.

    • @Mike37373
      @Mike37373 4 ปีที่แล้ว

      why is openlibrary.org/search.json empty?

  • @Andy801_dawless_music
    @Andy801_dawless_music 4 ปีที่แล้ว

    so much useful info in 25 mins 😄 thanks!

  • @mellocamilo
    @mellocamilo 3 ปีที่แล้ว

    Awesome tutorial!! thanks for this high quality work!

  • @lexternal
    @lexternal 2 ปีที่แล้ว

    thanks, great tutorial. prob one of the best i ever watch

  • @TiberiusGracchi
    @TiberiusGracchi 2 ปีที่แล้ว

    Very good information, especially the part about using useCallback instead of ref. I was just wondering how to grab the last node.

  • @marcusmaiialima
    @marcusmaiialima 3 ปีที่แล้ว

    Thank man!! It was very simple to implement and add to the project.

  • @djmilen4o
    @djmilen4o 4 ปีที่แล้ว

    Nice and clean tutorial! Very good explained!

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

    A react native tutorial on this would also be awesome. Currently building an app with native.

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

      I don't like mobile development so there probably won't be much if any React Native on my channel.

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

    I learned a lot from this video. Thank you, Kyle.

  • @priyasivakumar3607
    @priyasivakumar3607 2 ปีที่แล้ว

    Nailed it. Thanks for the Topic

  • @yorkwebsolution8986
    @yorkwebsolution8986 4 ปีที่แล้ว

    Very simple explanation. thanks alot

  • @riankrishandi
    @riankrishandi 3 ปีที่แล้ว

    nice tutorial , clear explanation , thanks bro

  • @md.akib5124
    @md.akib5124 5 ปีที่แล้ว

    wow you just taught us to make a node_module. Thank you so much

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

    Really good content kyle, please make video on lazy loading and interceptor in react (:

  • @BhushanDhage
    @BhushanDhage 4 ปีที่แล้ว

    Awesome explanation 👌🤩

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

    Nice tutorial. Although it's more correct semantically to use useEffect for attaching and disconnecting an observer on the last visible node rather than using useCallback like you did. Thanks for your videos!

    • @quoccuong1733
      @quoccuong1733 3 ปีที่แล้ว

      Is there a difference though. Ive doing it the useEffect way but wonder if 2 methods differ in any way

    • @yassinerassy6840
      @yassinerassy6840 2 ปีที่แล้ว

      Can you provide more details why ?

  • @chronotriggered204
    @chronotriggered204 4 ปีที่แล้ว

    Wow, infinite scrolling was simplified many thanks, your explanations help me grok

  • @hakanaki
    @hakanaki 3 ปีที่แล้ว

    Love Your Videos bro 👏👏

  • @roshanlalsahu7846
    @roshanlalsahu7846 2 ปีที่แล้ว

    we can also use debounce as an alternative to cancelling API call

  • @mehinhuseynova1426
    @mehinhuseynova1426 3 ปีที่แล้ว

    Thank You. :) Works like a charm

    • @nikhilsannat
      @nikhilsannat 3 ปีที่แล้ว

      cancelToken working?

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

    Nice tutorial. This works smoothly for text based results. But it will struggle to render list of complex React components when list becomes huge. Can we also have a React window tutorial

  • @rva3674
    @rva3674 4 ปีที่แล้ว

    The best tutorial in youtube!!!

  • @said-magomeddzhabrailov7911
    @said-magomeddzhabrailov7911 ปีที่แล้ว

    Thanks for the great content!

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

    Very good tutorial, but what if we don't use axios, instead we are using vanilla xmlhttprequest, how do we do throttling effect in this circumstances ?

  • @gautamv2046
    @gautamv2046 4 ปีที่แล้ว

    Really appreciate your work, simplest of all

    • @frontendHacks
      @frontendHacks 2 ปีที่แล้ว

      th-cam.com/video/c0nKjMnDfG4/w-d-xo.html&ab_channel=Front-EndHacks
      Watch Infinite Scroll Video here in Hindi

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

    Hey Kyle, thanks for the amazing tutorial, appreciate your work. I know this is an older video but had a quick question if you ever had the chance to read this, I can't figure out why the function inside the useCallback() where you defined the intersection observer get's called 4 times each time an intersection is observed. Best.

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

      Its being called twice, the first time you feed the target (node ) to the observer and the second when the target intersects with its intersection root (the scrollable div container)

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

    Thank you so much, useful❤

  • @HOSS11H
    @HOSS11H 3 ปีที่แล้ว

    Very Useful Thank you saved my day

  • @shahzaibriaz6552
    @shahzaibriaz6552 3 ปีที่แล้ว

    Please explain a little bit about intersectionObserver api and how did you identity that you've to use "useRef" hook with Intersection Observer API

  • @gaming24x75
    @gaming24x75 2 ปีที่แล้ว

    You Solved My Problem Thanks Sir

  • @kemcadams7210
    @kemcadams7210 4 ปีที่แล้ว

    This is a great example - thanks

  • @xunianzu
    @xunianzu 3 ปีที่แล้ว

    This is very helpful. Thank you.

  • @GBG731
    @GBG731 3 ปีที่แล้ว

    Great video, good job!

  • @dongnguyen-vn5ps
    @dongnguyen-vn5ps 2 ปีที่แล้ว

    we can extract to a custom hook to observe an element whether it is in viewport or not

  • @rideforworld
    @rideforworld 4 ปีที่แล้ว

    congrats for your engagement!

  • @awekeningbro1207
    @awekeningbro1207 2 ปีที่แล้ว

    Kyle looks like a totally different person from this video to now, both in bodily movements and thinking

  • @superbin6021
    @superbin6021 2 ปีที่แล้ว

    Thank you, handsome teacher