How to scroll to element in React

Issue #648

In a similar fashion to plain old javascript, note that href needs to have valid hash tag, like #features

1
2
3
4
5
6
7
8
9
10
11
<a
href='#features'
onClick={() => {
const options = {
behavior: 'smooth'
}
document.getElementById('features-section').scrollIntoView(options)
}}
>
Features
</a>

Updated at 2020-05-06 08:36:21

Comments