Writing code for the Scroller library and exporting it for users.
Writing a hook#
Open up the Scroller directory and navigate to the
src directory. Create a new file called
useScroller.js. Enter the following code:
Let's break down what each line of the code above is doing. We'll start by exporting a function called
useScroller which takes an options object which will tell us where to scroll to in the x/y coordinates, and if we should scroll smoothly.