Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the index when scroll the mouse? #203

Open
bfang711 opened this issue Jan 25, 2018 · 1 comment
Open

How to get the index when scroll the mouse? #203

bfang711 opened this issue Jan 25, 2018 · 1 comment

Comments

@bfang711
Copy link

bfang711 commented Jan 25, 2018

When I scroll the mouse down, I would like to get the index or [first Visible index, last Visible index]. I would like to use getVisibleRange(), however not successful. Here are what I tried.

class ChildElement extends React.Component
{    render() {
        return (<h1>Hello, world {this.props.id} </h1>);
}}
const renderItem = (index, key) =>
      <div key ={key}>
        <ChildElement id={index}/>
      </div>;

export class AnalysisPage extends React.Component {
//...constructor details here.....

//Way #1 failed
    componentDidUpdate(prevProps, prevState) {
//this doesn't work, seems like after rendering, the scroll doesn't update the whole component anymore.
        console.log(this.refs.inflist.getVisibleRange());    
    }

//Way #2 failed
    handleScroll(){
//this doesn't work property either. As I shown on the attached graph. The returned array are most [undefined, undefined].
        console.log(this.refs.inflist.getVisibleRange());   
    }

    render() {
        var myProps =
            {
                length: 10000,
                itemRenderer: renderItem,
                type: 'uniform',
                useStaticSize: true,
            };
        return (
            <div>
              <div>
                <p>{this.state.range}</p>
              </div>
              <div style={{height:300, overflow: 'auto'}} onScroll={this.handleScroll}>
                <ReactList id = "inflist" ref = "inflist" {...myProps}/>
              </div>
             </div>
        );
    }

image

So my question is what the way to get the index as a result of the action of scrolling the mouse.
thank you.

@bfang711
Copy link
Author

bfang711 commented Jan 25, 2018

Some corrections.
Way #2 using handleScroll() works properly only when I click the up/down arrow of the scrollbar. However if I drag the scroll bar to somewhere, it returns as above [undefined, undefined].

Do we know how to get this working properly?

thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant