Skip to content

Commit 69e9afc

Browse files
committed
🐛 fixed the infinte scroll
1 parent a20f603 commit 69e9afc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/App.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const App = () => {
2626
photos:
2727
page === 1
2828
? [...paginatedData]
29-
: prev.sellers.concat([...paginatedData]),
29+
: prev.photos.concat([...paginatedData]),
3030
isLoading: false
3131
}));
3232
}
@@ -36,19 +36,22 @@ const App = () => {
3636
useEffect(() => {
3737
fetchPhotos(1, 50);
3838
window.addEventListener("scroll", handleScroll);
39+
return () => {
40+
window.removeEventListener("scroll", handleScroll)
41+
}
3942
}, [fetchPhotos]);
4043

4144
const handleScroll = () => {
4245
if (
4346
window.innerHeight + window.scrollY >= document.body.offsetHeight - 300 &&
44-
!phtosData.isLoading
47+
!photosData.isLoading
4548
) {
4649
setPhotosData(prev => ({
4750
...prev,
4851
page: prev.page + 1,
4952
isLoading: true
5053
}));
51-
fetchPhotos(photosData.page + 1, photosData.perPage);
54+
fetchPhotos(photosData.page + 1, 50);
5255
}
5356
};
5457

0 commit comments

Comments
 (0)