I'm trying to create a scroll to element but I'm getting this error
"TypeError: Cannot read property 'scrollIntoView' of null". By console logging mapRef I can see that I'm getting the correct div. console.log
export class FinderComponent extends PureComponent {
constructor(props) {
super(props);
this.mapRef = React.createRef();
}
renderMap() {
return <div block="StoreFinder" ref={this.mapRef}></div>;
}
renderStoreCard(store) {
this.mapRef.current.scrollIntoView({ behavior: "smooth" });
//console.log(this.mapRef.current);
return (
<div
block="StoreFinder"
elem="Store"
key={store_name.replace(/\s/g, "")}
mods={{ isActive: store_name === selectedStoreName }}
>
{this.renderStoreCardContent(store)}
<button
block="Button"
mods={{ likeLink: true }}
onClick={() => changeStore(store)}
>
{__("Show on the map")}
</button>
</div>
);
}
}