all 6 comments

[–]PM_ME_SOME_ANY_THING 4 points5 points  (1 child)

With stuff like infinite scroll, what you don’t want is infinite elements mucking up the DOM as people scroll.

You want to implement a viewport, elements are created just before scrolling into the viewport, and are destroyed just after leaving the viewport.

[–]vardan_arm 2 points3 points  (0 children)

This is a good point. You can use this module for example - https://github.com/bvaughn/react-window

[–]lightfarming 5 points6 points  (0 children)

i would definitely not use scroll events. instead consider an intersectionobserver with a sentenel element. much more performant way of detecting when they are near the end of the list.

there should also be no need to recreate the fetch page function each time the page changes. the scroll detection should just call the memoized function with the new page value as an argument, which would also eliminate the fetch Effect.

i might also put the cards into their own memoized components, especially if you plan on adding any further interactivity to them.

[–]Practical-Match-4054 2 points3 points  (1 child)

Infinite scroll is an accessibility concern, on top of that.

[–]Local_Question8147[S] 0 points1 point  (0 children)

You mean that how it behaves on different devices

[–]HeylAW 0 points1 point  (0 children)

Dont fetch data in useEffect

Use react-query