This video is available to students only

Implementing Scroller

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.

React defines a few rules and best practices when using hooks. One common practice is to name a hook starting with use.

 

This page is a preview of Creating React Libraries from Scratch

Start a new discussion. All notification go to the author.