由于原始解决方案是为 react的 早期版本提供的,因此这里进行了更新:
constructor(props) { super(props) this.myRef = React.createRef() // Create a ref object }componentDidMount() { this.myRef.current.scrollTo(0, 0);}render() { return <div ref={this.myRef}></div> } // attach the ref property to a dom element


