Here you would add the event listener in by calling window.addEventListener in react’s componentDidMount lifecycle method.. You would have needed to create a function that will then handle the event and so it is also visible within the other lifecycle methods, such as componentWillUnmount.. When a user scrolls a DOM scroll event is fired, an event which is built into ever browser by default. React使用笔记(3)-React Event Listener… You can gain access to the actual HTML element by creating a React reference and passing it to the element itself. Passive listeners cannot cancel event propagation. According to React-Hooks reference guide, useRef() is useful for more than the ref attribute. See … import React, { createRef } from 'react' class ActionButton extends React.Component { constructor() { super() this.buttonRef = createRef() } render() { const { label, action } = this.props return (