My React component is as follows :
var ContentBox = React.createClass({
componentDidMount:function() {
this.getContents();
},
getContents:function() {
$.ajax({
url : ......
success:function(contents) {
this.setState({
contents : contents
});
}.bind(this)
});
},
componentDidUpdate:function() {
ReactDOM.findDOMNode(this).scrollTop = 0;
}
});
Essentially, what I'm trying to do is that when the page is rendered, I want to scroll to the top of the page. The "contents" change depending on the route parameters.
I've tried the solution given in Scroll to the top of the page after render in react.js But it's not working on mine.
UPDATE : The following worked
componentDidUpdate:function() {
ReactDOM.findDOMNode(this).scrollIntoView();
}
Why doesn't ReactDOM.findDOMNode(this).scrollTop = 0;
work? Also, I've tried $(window).scrollTop()
but that also doesn't work. I tried to put them in the "success" function of the AJAX request, but that doesn't work either.