I am trying to get the scroll position of a div in React. I tried getting the window the scroll values the values are always 0.
handleScrollPosition(e){
sessionStorage.setItem("scrollPosition", this.myRef.current!.scrollTop.toString());
};
<SearchListWrapper className="TestSL" ref={this.myRef} onScroll={this.handleScrollPosition} >
<StyledLink onClick={ () =>{ this.onClickResult(); } } >
</StyledLink>
</SearchListWrapper>
On click of StyledLink the new page is loaded. When I go back(with browser's back button) from the newly loaded page, I want to restore the position of scroll on SearchListWrapper .