Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

reactjs - How to use public method updatePosition of react-virtualized?

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

But I checkout the source: https://github.com/bvaughn/react-virtualized/blob/master/source/WindowScroller/WindowScroller.js

It's not a public method, so how can I use this method to update scroll position when other element size changed?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

But I checkout the source...It's not a public method

It's right here and it has some unit tests too.

To use it you'll need to set a ref to WindowScroller. Here's a minimal example of what I mean:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...