小编典典

如何使用公共方法updatePosition进行react-virtualized?

reactjs

的文档:https :
//github.com/bvaughn/react-
virtualized/blob/master/docs/WindowScroller.md#updateposition

但是我签出了源代码:https :
//github.com/bvaughn/react-
virtualized/blob/master/source/WindowScroller/WindowScroller.js

这不是公共方法,因此当其他元素大小更改时,如何使用此方法更新滚动位置?


阅读 392

收藏
2020-07-22

共1个答案

小编典典

但是我检查了源代码…这不是公共方法

这是在这里,它有一些单元测试过

要使用它,您需要将ref设置为WindowScroller。这是我的意思的一个最小示例:

class YourComponent extends React.Component {
  render() {
    return (
      <WindowScroller
        ref={this._setRef}
        {...otherProps}
      />
    );
  }

  _setRef = ref => {
    this.windowScrollerRef = ref;
  }

  someOtherMethod() {
    // Assuming you've mounted, you can access public methods like:
    this.windowScrollerRef.updatePosition();
  }
}
2020-07-22