How to scroll to element of the list in other component?
class Posts extends Components {
render() {
<ul>
{this.props.posts.map((post) =>
<li key={post.id}>{post.title}</li>
)}
</ul>
}
//redux
}
class OtherComponent extends Components {
onClickHandler = (id) => {
//!!!!!!!!
//scroll page to li with key={post.id}
}
render() {
<div>
{this.props.posts.map((post) =>
<div key={post.id} onClick={() => this.onClickHandler(post.id)}>{post.title}</div>
)}
</div>
}
//redux
}
I found solutions here: ReactJS how to scroll to an element
but all are for single element.
If I have list, I need to create a reference to everyone? The list of posts can change, so I can not do it.