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

我有一个问题,我没有想法,如何解决
在我的反应组件中,我显示了一长串数据,底部链接很少。
点击任何链接后,我填写新的链接集合列表,需要滚动到顶部。

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

'use strict';

// url of this component is #/:checklistId/:sectionId

var React = require('react'),Router = require('react-router'),sectionStore = require('./../stores/checklist-section-store');


function updateStateFromProps() {
  var self = this;
  sectionStore.getChecklistSectionContent({
    checklistId: this.getParams().checklistId,sectionId: this.getParams().sectionId
  }).then(function (section) {
    self.setState({
      section,componentReady: true
    });
  });

    this.setState({componentReady: false});
 }

var Checklist = React.createClass({
  mixins: [Router.State],componentwillMount: function () {
    updateStateFromProps.call(this);
  },componentwillReceiveProps(){
    updateStateFromProps.call(this);
   },render: function () {
  if (this.state.componentReady) {
    return(
      <section 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}`>
          Next Section
        </a>
      </section>
    );
    } else {...}
  }
});

module.exports = Checklist;
最后我用:
componentDidMount () {
  window.scrollTo(0,0)
}

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...