1- import { MutableRefObject , useEffect , useMemo , useRef , useState } from 'react'
1+ import { MutableRefObject , useState , useEffect , useRef , useMemo } from 'react'
22import { PostListItemType } from 'types/PostItem.types'
33
44export type useInfiniteScrollType = {
@@ -8,18 +8,16 @@ export type useInfiniteScrollType = {
88
99const NUMBER_OF_ITEMS_PER_PAGE = 10
1010
11- const useInfiniteScroll = (
11+ const useInfiniteScroll = function (
1212 selectedCategory : string ,
1313 posts : PostListItemType [ ] ,
14- ) : useInfiniteScrollType => {
14+ ) : useInfiniteScrollType {
1515 const containerRef : MutableRefObject < HTMLDivElement | null > =
1616 useRef < HTMLDivElement > ( null )
1717 const observer : MutableRefObject < IntersectionObserver | null > =
1818 useRef < IntersectionObserver > ( null )
1919 const [ count , setCount ] = useState < number > ( 1 )
2020
21- const containerRefNode = containerRef . current
22-
2321 const postListByCategory = useMemo < PostListItemType [ ] > (
2422 ( ) =>
2523 posts . filter (
@@ -49,14 +47,14 @@ const useInfiniteScroll = (
4947 useEffect ( ( ) => {
5048 if (
5149 NUMBER_OF_ITEMS_PER_PAGE * count >= postListByCategory . length ||
52- containerRefNode === null ||
53- containerRefNode . children . length === 0 ||
50+ containerRef . current === null ||
51+ containerRef . current . children . length === 0 ||
5452 observer . current === null
5553 )
5654 return
5755
5856 observer . current . observe (
59- containerRefNode . children [ containerRefNode . children . length - 1 ] ,
57+ containerRef . current . children [ containerRef . current . children . length - 1 ] ,
6058 )
6159 } , [ count , selectedCategory ] )
6260
0 commit comments