DEV Community

Adrian Bece
Adrian Bece

Posted on

4 1

React Custom Hooks: Scroll Indicator

Hello everyone, this is my first post here.

I've created this simple, but versatile React hook that keeps track of user's scroll. You can see these elements on blogs or news sites where user can keep track of how much of the article they've read.

It can keep track of scrolling of the whole page or on a certain element. It returns the percentage of the page or element scrolled (viewed).

You can find the npm package, alongside with the readme, here: https://www.npmjs.com/package/react-use-scroll-indicator

Let me know what you think or if you have any questions or comments.

Edit: I am working on an article on creating the custom React hooks. I will post is as soon as it's out. So if you are looking for a good starting point on learning the tricks of creating custom hooks, watch for my upcoming post. Thank you.

Top comments (0)

typescript

11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!