Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

how to get active item #160

Open
kannanseeni opened this issue May 3, 2020 · 1 comment
Open

how to get active item #160

kannanseeni opened this issue May 3, 2020 · 1 comment

Comments

@kannanseeni
Copy link

<Scrollspy items={ ['aboutus', 'bill', 'finance', 'global', 'contact' ] } currentClassName="ant-menu-item-selected" onUpdate={ (el) => { alert(el.items[id]) } }>

getting error

@caiojhonny
Copy link

You can get the active item on this way:

constructor(props) {
    super(props);
    this.scrolllist = React.createRef();
    this.activeItem = this.activeItem.bind(this);
  }
activeItem = () => {
    const indexActive = this.scrolllist.current.state.inViewState.findIndex(
      (x) => x === true
    );
    console.log(this.scrolllist.current.props.items[indexActive]);
  };
<Scrollspy 
ref={this.scrolllist}
items={ ['aboutus', 'bill', 'finance', 'global', 'contact' ] } 
currentClassName="ant-menu-item-selected" 
onUpdate={ (el) => { alert(el.items[id]) } }
>

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

No branches or pull requests

2 participants