Infinite Scrolling With React - Tutorial

  Рет қаралды 351,096

Web Dev Simplified

Web Dev Simplified

Күн бұрын

Infinite scrolling is incredibly common especially in social media applications, but it is intimidating to setup. In this video I will be breaking down exactly how to setup infinite scrolling and why it is much easier than it appears. Infinite scrolling is really just a fancy type of pagination that will paginate without the user needing to click a button. This means that we can setup simple pagination, but instead of hooking it up to a button we need to hook it up to scrolling. Setting up a JavaScript event on scroll is not very performant, though, so we will be using the amazing InteresectionObserver API to efficiently check for when the last element of our list is loaded.
🚨 IMPORTANT:
If you want to learn React in depth checkout my full modern React course.
courses.webdevsimplified.com/...
📚 Materials/References:
GitHub Code: github.com/WebDevSimplified/R...
🧠 Concepts Covered:
- How to use React hooks
- useEffect, useState, useRef, useCallback hooks
- IntersectionObserver with React
🌎 Find Me Here:
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
#React #WDS #InfiniteScrolling

Пікірлер: 331
@jefffideler8046
@jefffideler8046 3 жыл бұрын
Gotta say...this is probably the best, most straightforward tutorial I've ever seen!
@Mike37373
@Mike37373 3 жыл бұрын
why is openlibrary.org/search.json empty?
@jefffideler8046
@jefffideler8046 3 жыл бұрын
@@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 3 жыл бұрын
i agree
@fluntimes
@fluntimes 4 жыл бұрын
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.
@Doom_C
@Doom_C 4 жыл бұрын
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!
@toaninh2668
@toaninh2668 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
@LinkSake
@LinkSake 4 жыл бұрын
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.
@xanderav
@xanderav 3 жыл бұрын
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 2 жыл бұрын
No need to apologize for your English. it was understandable.
@nishantmogha7679
@nishantmogha7679 2 жыл бұрын
Or you can just use the array, [] is falsy.
@limitless9483
@limitless9483 2 жыл бұрын
@@nishantmogha7679 array [] and {} are truthy brah
@limitless9483
@limitless9483 2 жыл бұрын
Also to make sure the app won't crash when array is null use optional chaining like myArr?.length
@xxxyy7452
@xxxyy7452 2 жыл бұрын
You can do that, but sometimes clearly code better than clever code
@akarshsrivastava8890
@akarshsrivastava8890 2 жыл бұрын
Kyle, you are great. Never found a tutor explaining such complex topics so easily. 😊
@rajapavithraselvaraj5937
@rajapavithraselvaraj5937 Жыл бұрын
I really have to say.. this was the best, clear, very staright forward tutorial. AWESOME
@acedecastro83
@acedecastro83 4 жыл бұрын
Learned a lot from this. Thank you so much Kyle 🙏🏼
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
You're welcome!
@isaacpriestley
@isaacpriestley Жыл бұрын
Your tutorials are incredible! It's so much great information in such a concise presentation.
@jairocket
@jairocket 2 жыл бұрын
This tutorial is amazing! Thank you very much for making it simpler!
@sahaneakanayaka3394
@sahaneakanayaka3394 Жыл бұрын
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 😍😍
@uszeyboi
@uszeyboi 3 жыл бұрын
Thank you so much! I was struggling with window object so long and finally your video helped me!
@frontendHacks
@frontendHacks 2 жыл бұрын
kzbin.info/www/bejne/mWHRfJ2Do6mZfZY&ab_channel=Front-EndHacks Watch Infinite Scroll Video here in Hindi
@johnbox5540
@johnbox5540 3 жыл бұрын
awesome video. infinite scrolling starts at 17:50
@Rodo1802
@Rodo1802 8 ай бұрын
This is a great tutorial, straight to the point and clear. Thank you, Kyle!
@usamatahir6413
@usamatahir6413 3 жыл бұрын
Thanks for the tutorial. This is probably the best, most straightforward tutorial
@nalladileepreddy1436
@nalladileepreddy1436 3 жыл бұрын
Never saw any better explaination than this, thank you ..
@MaxAigner
@MaxAigner Жыл бұрын
I am really impressed by this tutorial, it helped me a lot in my current react project, thank you!
@rizqyhbb
@rizqyhbb Жыл бұрын
just from this video I have learned so many things, mainly the useRef and useCallback. thankyou
@amitpareek8905
@amitpareek8905 4 жыл бұрын
Amazing video. You have made a complex thing look so easy. Keep up the great work!! Thank you!
@frontendHacks
@frontendHacks 2 жыл бұрын
kzbin.info/www/bejne/mWHRfJ2Do6mZfZY&ab_channel=Front-EndHacks Watch Infinite Scroll Video here in Hindi
@anshshrivastava9107
@anshshrivastava9107 3 жыл бұрын
Thanks for this man, exactly what I was looking for, now I can create what I wanted. THANKSSSSSSSSSSSSSS
@sergiodfm
@sergiodfm 4 жыл бұрын
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.
@user-rm6rb3tp5u
@user-rm6rb3tp5u 2 жыл бұрын
This react lecture is AMAZING... Thanks from Korea.
@mellocamilo
@mellocamilo 3 жыл бұрын
Awesome tutorial!! thanks for this high quality work!
@djmilen4o
@djmilen4o 4 жыл бұрын
Nice and clean tutorial! Very good explained!
@ismoilshokirov
@ismoilshokirov 3 жыл бұрын
Really good approach, dude your video helped me a lot to finish my project at work, Thank you so much
@aryavats5403
@aryavats5403 Жыл бұрын
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!
@chexter-wang
@chexter-wang 2 жыл бұрын
This is so easy to use and does help a lot! Thank you for the video!
@NikhilAdiga
@NikhilAdiga 2 жыл бұрын
Thank you so much! None of the other solutions worked for me except this!
@DieterWiesflecker
@DieterWiesflecker 3 жыл бұрын
Very very straightforward, keep the good work and thanks!
@ankitmehrotra8519
@ankitmehrotra8519 4 жыл бұрын
Thanks a lot Kyle. All of your videos are top notch..
@mayurborse1745
@mayurborse1745 4 жыл бұрын
Awesome. Just what I was looking for. I used it in photo grid and full screen view in my app. Thanks
@brunamarques580
@brunamarques580 11 ай бұрын
Thank you so much for this tutorial, it literally helped me pass in a interview test 👏
@waynes9744
@waynes9744 4 жыл бұрын
I learned a lot from this video. Thank you, Kyle.
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
You are very welcome
@razzsawhoney2818
@razzsawhoney2818 3 жыл бұрын
Thanks man. A much needed tutorial for me...
@eternl_sunshine22
@eternl_sunshine22 4 ай бұрын
thanks!! used your pagination api with this, tweaked it a little as i'm using sequelize and it works great.
@marcusmaiialima
@marcusmaiialima 3 жыл бұрын
Thank man!! It was very simple to implement and add to the project.
@viratkohli-jr6md
@viratkohli-jr6md 2 жыл бұрын
Cool . Got my all doubt cleared. Nice work
@Andy801_dawless_music
@Andy801_dawless_music 4 жыл бұрын
so much useful info in 25 mins 😄 thanks!
@lexternal
@lexternal Жыл бұрын
thanks, great tutorial. prob one of the best i ever watch
@chronotriggered204
@chronotriggered204 4 жыл бұрын
Wow, infinite scrolling was simplified many thanks, your explanations help me grok
@koladeleolaitan
@koladeleolaitan Жыл бұрын
Just used this at work. Thank you Kyle!
@kingsleyakindele5389
@kingsleyakindele5389 3 жыл бұрын
A very great tutorial man.
@hamedbahram
@hamedbahram 3 жыл бұрын
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 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)
@rva3674
@rva3674 4 жыл бұрын
The best tutorial in youtube!!!
@faris.abuali
@faris.abuali Жыл бұрын
Great explanation! Thanks Kyle!
@mohammadaldibes6879
@mohammadaldibes6879 2 жыл бұрын
The best tutorial I've ever seen
@whereismyjuliet
@whereismyjuliet 3 жыл бұрын
Amazing tutorial, as special the approach to trigger the axios function via IntersectionObserver instead of div.scrollHeight.
@parasarora5869
@parasarora5869 4 жыл бұрын
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 4 жыл бұрын
Intersection Observer is a bit complex, but it makes doing things like infinite scrolling so much easier.
@parasarora5869
@parasarora5869 4 жыл бұрын
@@WebDevSimplified yes.. absolutely correct
@mcy93w
@mcy93w 3 жыл бұрын
24k pure gold. Thank you so much!
@itsatimemachine
@itsatimemachine 2 жыл бұрын
your videos are awesome-- thank you! also, happy new year
@RizaHariati
@RizaHariati 2 жыл бұрын
The intersectionObserver is awesome!! so much more practical!
@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 жыл бұрын
kzbin.info/www/bejne/mWHRfJ2Do6mZfZY&ab_channel=Front-EndHacks Watch Infinite Scroll Video here in Hindi
@fab313
@fab313 4 жыл бұрын
Great lesson. Thank you!
@user-ci5cq5il1s
@user-ci5cq5il1s 4 ай бұрын
Thank you for making such an understandable and useful lessons! You're really great🙏💛
@jhmesseroux
@jhmesseroux 2 жыл бұрын
incredible bro i appreciate this🙌 kind of content
@soultouchingsongs
@soultouchingsongs 4 жыл бұрын
Thanks a lot for the video🙏. Finally understood infinite scrolling.👍
@charliesoandso
@charliesoandso 4 жыл бұрын
This is outstanding. Thanks :D
@gautamv2046
@gautamv2046 3 жыл бұрын
Really appreciate your work, simplest of all
@frontendHacks
@frontendHacks 2 жыл бұрын
kzbin.info/www/bejne/mWHRfJ2Do6mZfZY&ab_channel=Front-EndHacks Watch Infinite Scroll Video here in Hindi
@romihasan380
@romihasan380 3 жыл бұрын
you've a better solution than using scroll position broo, good job!!
@user-fk6mr5dr9k
@user-fk6mr5dr9k 4 жыл бұрын
just amazing! perfect! thanks
@ankurkhera11
@ankurkhera11 4 жыл бұрын
Thanks a lot. Great explanation!!
@md.akib5124
@md.akib5124 4 жыл бұрын
wow you just taught us to make a node_module. Thank you so much
@said-magomeddzhabrailov7911
@said-magomeddzhabrailov7911 Жыл бұрын
Thanks for the great content!
@yorkwebsolution8986
@yorkwebsolution8986 3 жыл бұрын
Very simple explanation. thanks alot
@riankrishandi
@riankrishandi 3 жыл бұрын
nice tutorial , clear explanation , thanks bro
@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
@ashishkumawat6110
@ashishkumawat6110 Жыл бұрын
Very clever implementation!
@kemcadams7210
@kemcadams7210 4 жыл бұрын
This is a great example - thanks
@xunianzu
@xunianzu 3 жыл бұрын
This is very helpful. Thank you.
@AjithAbinashSS
@AjithAbinashSS Жыл бұрын
Great Tutorial... Helped a lot
@BhushanDhage
@BhushanDhage 3 жыл бұрын
Awesome explanation 👌🤩
@cod3a
@cod3a Жыл бұрын
thanks bro, very useful :)
@Nexjsdeveloper
@Nexjsdeveloper 3 ай бұрын
Thank you so much, useful❤
@rideforworld
@rideforworld 4 жыл бұрын
congrats for your engagement!
@Nil-js4bf
@Nil-js4bf Жыл бұрын
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
@syedumair3172
@syedumair3172 2 жыл бұрын
Learned a lot! Thanks
@GBG731
@GBG731 3 жыл бұрын
Great video, good job!
@magicfibre
@magicfibre 2 жыл бұрын
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.
@Ann-eb8hh
@Ann-eb8hh Жыл бұрын
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 11 ай бұрын
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 8 ай бұрын
Great explanation
@aronhegedus
@aronhegedus 2 жыл бұрын
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!
@victorjordan889
@victorjordan889 Жыл бұрын
Amazing content! Thanks a lot!
@priyasivakumar3607
@priyasivakumar3607 2 жыл бұрын
Nailed it. Thanks for the Topic
@HOSS11H
@HOSS11H 2 жыл бұрын
Very Useful Thank you saved my day
@TiberiusGracchi
@TiberiusGracchi Жыл бұрын
Very good information, especially the part about using useCallback instead of ref. I was just wondering how to grab the last node.
@akshayjadhav2418
@akshayjadhav2418 4 жыл бұрын
Really good content kyle, please make video on lazy loading and interceptor in react (:
@joelspinelli3701
@joelspinelli3701 2 жыл бұрын
great tutorial, thanks!
@ramusesandasari8451
@ramusesandasari8451 10 ай бұрын
Awesome Tut
@avneet12284
@avneet12284 4 жыл бұрын
O boy !! That was excellent 👍👌
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Thank you!
@reedstewart8413
@reedstewart8413 4 жыл бұрын
Great video! I've been watching your React videos for some time now and was just wondering why you use es5 functions instead of es6 arrow functions? Again really good video!
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
It really depends on the use case. I find that if I am creating a named function such as function someName() {} then I use a normal function, but when I am nesting function calls in callbacks or making anonymous function calls like this someOtherFunction(() => {}) then I use an arrow function. It really depends, though, and for the most part I use arrow functions.
@mattmarkus4868
@mattmarkus4868 2 жыл бұрын
to be honest, I find the old school function() easier on the eyes. I only use => when doing anonymous functions and call backs like he said ^. But if it's just a function on the component, I like the look of the "es5" way.
@manimarann1457
@manimarann1457 4 жыл бұрын
Thanks for such an amazing vedio bro.
@gaming24x75
@gaming24x75 2 жыл бұрын
You Solved My Problem Thanks Sir
@invictuz4803
@invictuz4803 4 жыл бұрын
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.
@kat802
@kat802 2 жыл бұрын
thanks dude, u save my job. button like for u
@hakanaki
@hakanaki 3 жыл бұрын
Love Your Videos bro 👏👏
@foREVer1996123
@foREVer1996123 4 жыл бұрын
Amazing tutorial
@brinascode980
@brinascode980 4 жыл бұрын
Hey Kyle, what advantage did useCallback have here over a regular function, since it's using a dependency array anyway? Thanks for the video!
@posivibez2094
@posivibez2094 3 жыл бұрын
extremely helpful thank you
@diegor5805
@diegor5805 3 жыл бұрын
This is it! Nice!
@user-yo6vd5ov8k
@user-yo6vd5ov8k Жыл бұрын
thank you so much, man!
@dileepnagendra8199
@dileepnagendra8199 Жыл бұрын
Brilliant !!!
Learn Intersection Observer In 15 Minutes
15:32
Web Dev Simplified
Рет қаралды 320 М.
Simple Frontend Pagination | React
19:13
Traversy Media
Рет қаралды 475 М.
Василиса наняла личного массажиста 😂 #shorts
00:22
Денис Кукояка
Рет қаралды 9 МЛН
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 70 МЛН
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 8 МЛН
Final muy inesperado 🥹
00:48
Juan De Dios Pantoja
Рет қаралды 18 МЛН
React Intersection Observer (scroll + lazy-load  картинок)
22:10
Infinite Pagination Component With React Query
14:58
Cosden Solutions
Рет қаралды 15 М.
Animating a Stick Fight in 10 Seconds vs 10 Hours
11:53
CyanSandwich
Рет қаралды 39 М.
Most Beginner React Developers Do This Wrong
13:47
Web Dev Simplified
Рет қаралды 225 М.
Add Infinite Scrolling in React JS in Hindi 🔥
19:02
Thapa Technical
Рет қаралды 40 М.
Introduction to the Intersection Observer JavaScript API
22:11
Kevin Powell
Рет қаралды 175 М.
10 Tailwind Classes I Wish I Knew Earlier
13:31
Web Dev Simplified
Рет қаралды 166 М.
Василиса наняла личного массажиста 😂 #shorts
00:22
Денис Кукояка
Рет қаралды 9 МЛН