0

There is a library here called react-is-scrolling: https://www.npmjs.com/package/react-is-scrolling, however it seems to be outdated and I can't seem to get it to work. It does exactly what I need, I just need to detect if the user is scrolling or not. Ideally, it will detect them scrolling and change a certain image if they are scrolling. When using this library, I get this error:

Could not find module in path: 'react/lib/ReactComponentTreeHook' relative to '/node_modules/react-dom/15.6.2/lib/ReactDebugTool.js'

You can also check out my codesandbox here to get a closer look at it. Anything helps, thank you!

Thud Designs
  • 1
  • 1
  • 1
  • https://stackoverflow.com/questions/57453141/using-react-hooks-to-update-w-scroll – Andy Dec 28 '21 at 00:10
  • I think you are right that react-is-scrolling is incompatible with current versions of React. Use the approach in Andy's linked question ( window scroll event listener ) if you want to react to any kind of scrolling. This is what react-is-scrolling also used. If you want to react when certain dom element (like an image) is visible in the viewport as a result of user scrolling, check out [intersection observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) instead. https://github.com/thebuilder/react-intersection-observer – Håken Lid Dec 28 '21 at 00:26
  • Here's an older question similar to the one linked by Andy, but using class components (like in your codesandbox) instead of react hooks. If you are learning React, it's recommended to use function components and hooks instead of class components, and many current resources and answers on stackoverflow assume that you use hooks instead of class components. https://stackoverflow.com/questions/29725828/update-style-of-a-component-onscroll-in-react-js – Håken Lid Dec 28 '21 at 00:30

0 Answers0