makotot/react-scrollspy

how to get active item

Opened this issue · 1 comments

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

getting error

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]) } }
>