-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Comment InfiniteScroll 적용 및 Hook 추가(#80)
- usePageCounter Hook - Comment Infinite Scroll 추가
- Loading branch information
1 parent
5e80153
commit c8c9cb4
Showing
3 changed files
with
49 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useRef } from 'react'; | ||
|
||
export default function usePageCounter(initialCursor = 0) { | ||
const page = useRef<{ cursor: number; blocked: boolean }>(); | ||
|
||
if (!page.current) | ||
page.current = { | ||
cursor: initialCursor, | ||
blocked: false, | ||
}; | ||
|
||
return { | ||
isBlocked() { | ||
return page.current ? page.current.blocked : true; | ||
}, | ||
getNextCursor() { | ||
if (page.current) { | ||
page.current.blocked = true; | ||
return page.current.cursor + 1; | ||
} | ||
return initialCursor; | ||
}, | ||
confirmNextCursor() { | ||
if (page.current) { | ||
page.current.cursor += 1; | ||
page.current.blocked = false; | ||
} | ||
}, | ||
}; | ||
} |