mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
feat: useWindowScroll - for cross-browser compatibility
For cross-browser compatibility, use window.pageYOffset instead of window.scrollY. (https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY)
This commit is contained in:
parent
950f5edb77
commit
5987cc82cc
@ -9,8 +9,8 @@ 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(() => {
|
||||
@ -18,8 +18,8 @@ const useWindowScroll = (): State => {
|
||||
cancelAnimationFrame(frame.current);
|
||||
frame.current = requestAnimationFrame(() => {
|
||||
setState({
|
||||
x: window.scrollX,
|
||||
y: window.scrollY,
|
||||
x: window.pageXOffset,
|
||||
y: window.pageYOffset,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user