Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scrollen

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scrollen

A performant utility scroll hook for React

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Scrollen

A performant utility scroll hook for React.

Install

npm install scrollen

Getting Started

To start using the scrollen you need import and call the useScroller hook

import { useScroller } from 'scrollen'

const scroller = useScroller()

And that's it! By default the hook will listen to scroll on document.

If you want to use a different scroll container, you can use the setScrollerElement function

import { useScroller } from 'scrollen'

const scroller = useScroller()

<div ref={scroller.setScrollerElement}>
  ...
</div>

Example

See this small example of how you can use the hook.

Documentation

First of all, a huge thanks to @diegohaz as this library uses the Ariakit Component Stores API, so refer to the Ariakit Component Stores Guide to learn the core of the hook.

Props

PropDescription
initialScrollTopThe initial scrollTop value to the scroller element.
initialScrollLeftThe initial scrollLeft value to the scroller element.
startScrollAtWhere the scroll should start. You can pass bottom | right.

State

StateDescription
elementThe scroller element.
scrollTopThe scrollTop value for the scroller element.
scrollLeftThe scrollLeft value for the scroller element.
scrollWidthThe scrollWidth value for the scroller element.
scrollHeightThe scrollHeight value for the scroller element.
scrollYThe progress of the vertical scroll. (between 0 and 1)
scrollXThe progress of the horizontal scroll. (between 0 and 1)
scrollLengthYThe length of the vertical scroll.
scrollLengthXThe length of the horizontal scroll.
scrollDirectionYThe direction of the vertical scroll. (static | up | down)
scrollDirectionXThe direction of the horizontal scroll. (static | left | right)
isAtTopA boolean to check if the scroll reached the top.
isAtBottomA boolean to check if the scroll reached the bottom.
isAtLeftA boolean to check if the scroll reached the left.
isAtRightA boolean to check if the scroll reached the right.

Functions

FunctionDescription
setScrollerElementFunction to set the scroller element.
scrollToTopFunction to scroll programatically to top.
scrollToLeftFunction to scroll programatically to left.
scrollToBottomFunction to scroll programatically to bottom.
scrollToRightFunction to scroll programtically to right.
useOnScrollTopA custom hook to register a callback that is called when the scroll reached the top.
useOnScrollBottomA custom hook to register a callback that is called when the scroll reached the bottom.

Acknowledgements

  • Ariakit - Thanks to @diegohaz for the Component Stores API that made it possible to create a performant hook.
  • react-virtuoso - Where did I get ideas for utilities.

Keywords

FAQs

Package last updated on 13 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc