-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] 스크롤 끝 확인하는 부분 hook 파일 분리 #32
why 재사용 가능성이 있고 파일이 너무 길어지기 때문에 분리함 how hook 디렉토리안에 useScrollEnd로 분리
- Loading branch information
1 parent
aedf8cc
commit fb20c56
Showing
3 changed files
with
30 additions
and
30 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,26 @@ | ||
import React, { useState, useEffect } from "react"; | ||
const useScrollEnd = () => { | ||
// state를 생성합니다. | ||
const [state, setState] = useState(false); | ||
|
||
const onScroll = () => { | ||
if ( | ||
document.documentElement.scrollTop + | ||
document.documentElement.clientHeight === | ||
document.documentElement.scrollHeight | ||
) { | ||
console.log("scroll Y : ", window.scrollY); | ||
setState(true); | ||
} else { | ||
console.log("scroll Y! : ", window.scrollY); | ||
setState(false); | ||
} | ||
}; | ||
useEffect(() => { | ||
window.addEventListener("scroll", onScroll); | ||
return () => window.removeEventListener("scroll", onScroll); // <---- 집중 !!! | ||
}, []); | ||
return state; | ||
}; | ||
|
||
export default useScrollEnd; |