Skip to content

Commit

Permalink
feat: useWindowScroll - for cross-browser compatibility (#480)
Browse files Browse the repository at this point in the history
feat: useWindowScroll - for cross-browser compatibility
  • Loading branch information
streamich authored Jul 25, 2019
2 parents c58aac0 + 5987cc8 commit e37dd8d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/useWindowScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ export interface State {
const useWindowScroll = (): State => {
const frame = useRef(0);
const [state, setState] = useState<State>({
x: isClient ? window.scrollX : 0,
y: isClient ? window.scrollY : 0,
x: isClient ? window.pageXOffset : 0,
y: isClient ? window.pageYOffset : 0,
});

useEffect(() => {
const handler = () => {
cancelAnimationFrame(frame.current);
frame.current = requestAnimationFrame(() => {
setState({
x: window.scrollX,
y: window.scrollY,
x: window.pageXOffset,
y: window.pageYOffset,
});
});
};
Expand Down

0 comments on commit e37dd8d

Please sign in to comment.