I am using the react-scroll
library in order to handle scrolling on my React app. I want to scroll to the top whenever a specific button is clicked, however I do not want it to scroll smoothly, which seems to be enabled by default. I have tried the following code, however the page still scrolls smoothly, though the duration changed to 2 seconds successfully. I have tried other values for the smooth
property, such as easeInQuart
, etc., which worked perfectly. I tried putting false
in quotes as well, to no avail.
<button onClick={() => animateScroll.scrollToTop({
duration: 2000,
smooth: false
})}>
</button>
EDIT:
As Bronson pointed out below, the behavior is satisfied with the window.scrollTo
method. To clarify, I was wondering why the code above does not display the same behavior, otherwise what point is there to accepting a boolean
value for the smooth
property if it is always enabled?