Here it is in functional style with the useEffect hook:
useEffect(() => {
const onScroll = (event) => console.info("scrolling", event);
window.addEventListener('scroll', onScroll);
return () => {
window.removeEventListener('scroll', onScroll);
}
}, []);
More Related Contents:
- Why can’t I directly modify a component’s state, really?
- How to update nested state properties in React
- Why is setState in reactjs Async instead of Sync?
- React / JSX Dynamic Component Name
- console log the state after using useState doesn’t return the current value [duplicate]
- How do I render components with different layouts/elements using react-router-dom v6
- Update style of a component onScroll in React.js
- Rendering React Components from Array of Objects
- How to perform debounce?
- React input defaultValue doesn’t update with state
- How to add custom html attributes in JSX
- onClick doesn’t render new react component.
- How to assign refs to multiple components
- Access Control Origin Header error using Axios
- Node.js Sass version 7.0.0 is incompatible with ^4.0.0 || ^5.0.0 || ^6.0.0
- Warning: Function components cannot be given refs
- Using JavaScript Axios/Fetch. Can you disable browser cache?
- React.js ES6 avoid binding ‘this’ to every method
- Save data in a special order when click on button
- Axios posting params not read by $_POST
- Uncaught Invariant Violation: Too many re-renders. React limits the number of renders to prevent an infinite loop
- XMLHttpRequest cannot load No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:3000’ Google maps
- React, losing saved data in localStorage with useEffect after page refresh
- es6 – import all named module without alias
- Detect change in query param react-router-dom v4.x and re-render component
- Using document.querySelector in React? Should I use refs instead? How?
- How to load es6, react, babel code in html with cdn?
- How to render element on click of button: ReactJS
- Difference between React Component and React Element
- Want to have an event handler for the browser’s back button with next.js