如何使用react虚拟化的公共方法updatePosition?

IT技术 reactjs react-virtualized
2021-05-15 22:10:18

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

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

它不是公共方法,那么当其他元素大小发生变化时,如何使用此方法更新滚动位置?

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();
  }
}