class ArrowUp extends Component {
state = {
isVisible: false,
};
componentDidMount() {
window.addEventListener('scroll', this.handleScroll);
}
componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll);
}
handleScroll = () => {
if (window.scrollY >= SOME_VALUE && !this.state.isVisible) {
this.setState({ isVisible: true });
} else if (window.scrollY < SOME_VALUE && this.state.isVisible) {
this.setState({ isVisible: false });
}
};
render() { /* ... */ }
}