您想要的是
this.activateWayPoint在设置之前避免开火
scrollTop。
您可以通过将状态变量设置
waypointReady为
false初始来实现。在中将其设置为true
componentDidMount。
然后,您可以修改
this.activateWayPoint为check
this.state.waypointReady,如果为false,则立即返回。
// inside componentgetInitialState() { return { waypointReady : false }}componentDidMount() { this.refs.messages.scrollTop = this.refs.messages.scrollHeight; this.setState({ waypointReady : true});}activateWayPoint() { if (! this.state.waypointReady) return; // Your pre here! // ...}您可能必须
this在
render函数内部进行绑定:
// ...<Waypoint onEnter={this.activateWayPoint.bind(this)}/>// ...或者,
this.activateWayPoint您可以在render 内部执行检查,而不是在内部执行检查:
// ...<Waypoint onEnter={ this.state.waypointReady ? this.activateWayPoint : null }/>// ...这假设您的组件每次都重新渲染
setState。



