在react.js中呈现后滚动到页面顶部

我有一个问题,我没有办法解决。
在react组件中,我在底部显示了一长串数据和几个链接。
在点击任何一个链接后,我用新的链接集合填写列表,并需要滚动到顶部

问题是-呈现新集合后如何滚动到顶部

“严格使用”;
//此组件的url为#/:checklistId/:sectionId
var React=require('React'),
路由器=需要('react-Router'),
sectionStore=需要('./../stores/checklist section store');
函数updateStateFromProps(){
var self=这个;
sectionStore.getChecklistSectionContent({
checklistId:this.getParams().checklistId,
sectionId:this.getParams().sectionId
}).然后(功能(部分){
自我状态({
部分
组件就绪:true
});
});
this.setState({componentReady:false});
}
var Checklist=React.createClass({
mixins:[路由器.状态],
componentWillMount:函数(){
updateStateFromProps.call(this);
},
组件将接收道具(){
updateStateFromProps.call(this);
},
渲染:函数(){
if(this.state.componentReady){
返回(
<章节className='checklist-section'>
<header className='section-header'>{this.state.section.name}</header>
<Steps Steps={this.state.section.Steps}/>
<a href=`this.getParams().checklistId}/${this.state.section.nextSection.Id}`>
下一节
</a>
</section>
);
}否则{…}
}
});
module.exports=检查表;

最后。。我用过:

componentDidMount(){
滚动到(0,0)
}

编辑:React v16.8+

useffect(()=&gt{
滚动到(0,0)
}, [])

发表评论