Medium
Here is a component supposed to display the number of pixels scrolled vertically.
class Scroller extends React.Component{
constructor(props){
super(props);
this.state={distance: window.scrollY};
this.updateDistance= this.updateDistance.bind(this);
}
updateDistance(){
this.setState({distance: window.scrollY});
}
componentDidMount(){
window.addEventListener("scroll", this.updateDistance);
}
render(){
return(
<div style="height: 5000px">
<p style="position: fixed; top: 5px; left: 5px">
Scrolled{this.state.distance} pixels.
</p>
</div>
);
}
}
What is(are) the problem(s)?
Author: Victor SabatierStatus: PublishedQuestion passed 1565 times
Edit
4
Community EvaluationsNo one has reviewed this question yet, be the first!
7
Optimize a React component by implementing shouldComponentUpdate6
Write a React function that fetches comments and passes them to a component.3
Write a React component as a function7
How to submit a form in React7
Improve this React component so that it displays "Green" by default.3
Write the missing code to render the children of the UserProfile component.3
Optimize the following React component: