MCPcopy Create free account
hub / github.com/streamich/react-use / handler

Function handler

src/useWindowScroll.ts:18–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16
17 useEffect(() => {
18 const handler = () => {
19 setState((state) => {
20 const { pageXOffset, pageYOffset } = window;
21 //Check state for change, return same state if no change happened to prevent rerender
22 //(see useState/setState documentation). useState/setState is used internally in useRafState/setState.
23 return state.x !== pageXOffset || state.y !== pageYOffset
24 ? {
25 x: pageXOffset,
26 y: pageYOffset,
27 }
28 : state;
29 });
30 };
31
32 //We have to update window scroll at mount, before subscription.
33 //Window scroll may be changed between render and effect handler.

Callers 1

useWindowScrollFunction · 0.70

Calls 1

setStateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…