I've got a page with a table generated by a class component where, depending on some logic, I have only one of its rows "active" in a certain moment. I'm trying to scroll to the "active" row as the user opens the page.
I've already read this discussion but it didn't help ReactJS how to scroll to an element
Doing like this I get that this.scrollHere.current
is null
constructor(props) {
super(props);
this.scrollHere = React.createRef();
}
componentDidMount() {
// not using 'current', scrollIntoView() results not to be a function
this.scrollHere.current.scrollIntoView({behavior: 'smooth', block: 'start'})
}
render() {
return(
...
<tr ref={this.scrollHere}><td>...</td></tr>
...
)
}
Is that because the reference, when componentDidMount()
is called, doesn't yet exist? If so, how to make it work?