Skip to content

Commit

Permalink
feat(ui/hooks): useScroll 훅 추가 (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukvvon authored Jun 13, 2024
1 parent 5e80c90 commit a37682b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ui/hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @stylistic/padding-line-between-statements */
export { useBoolean } from './use-boolean';
export { useDisclosure } from './use-disclosure';
export { useScroll } from './use-scroll';
21 changes: 21 additions & 0 deletions packages/ui/hooks/src/use-scroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useEffect, useState } from 'react';

export function useScroll() {
const [scrollX, setScrollX] = useState(0);
const [scrollY, setScrollY] = useState(0);

function handleSetScrollXY() {
setScrollX(window.scrollX);
setScrollY(window.scrollY);
}

useEffect(() => {
window.addEventListener('scroll', handleSetScrollXY);

return () => {
window.removeEventListener('scroll', handleSetScrollXY);
};
}, []);

return { scrollX, scrollY };
}

0 comments on commit a37682b

Please sign in to comment.