Skip to content

Commit

Permalink
refactor: 의존성 배열 문제로 controlHeader 함수를 useEffect 안에 넣어주기
Browse files Browse the repository at this point in the history
  • Loading branch information
stopmin committed Jul 16, 2024
1 parent d9a5484 commit 2c9dbd8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const Header = () => {
const [show, setShow] = useState(true);
const [lastScrollY, setLastScrollY] = useState(0);

const controlHeader = () => {
if (window.scrollY > lastScrollY) {
setShow(false);
} else {
setShow(true);
}
setLastScrollY(window.scrollY);
};

useEffect(() => {
const controlHeader = () => {
if (window.scrollY > lastScrollY) {
setShow(false);
} else {
setShow(true);
}
setLastScrollY(window.scrollY);
};

window.addEventListener('scroll', controlHeader);

return () => {
Expand Down

0 comments on commit 2c9dbd8

Please sign in to comment.