react-use-scroll-sync
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

react-use-scroll-sync

npm version npm downloads

Custom react hook for synced scroll position across multiple scrollable elements.

preview

Demo

https://gk4m.github.io/react-use-scroll-sync/

Installation

Install it with yarn:

yarn add react-use-scroll-sync

Or with npm:

npm i react-use-scroll-sync --save

How to use

import * as React from "react"
import { useScrollSync } from "react-use-scroll-sync"
 
const App = () => {
  const ref1 = React.useRef<HTMLDivElement>(null)
  const ref2 = React.useRef<HTMLDivElement>(null)
 
  useScrollSync([ref1, ref2], {
    horizontal: true,
    vertical: true,
    proportional: true
  })
 
  return (
    <>
      <div
        ref={ref1}
        style={{ overflow: "auto", width: "300px", height: "300px" }}
      >
        <div style={{ width: "500px" }}>Lorem ipsum dolor sit amet...</div>
      </div>
 
      <div
        ref={ref2}
        style={{ overflow: "auto", width: "300px", height: "300px" }}
      >
        <div style={{ width: "500px" }}>Lorem ipsum dolor sit amet...</div>
      </div>
    </>
  )
}
 

License

MIT

Package Sidebar

Install

npm i react-use-scroll-sync

Weekly Downloads

4,498

Version

0.1.6

License

MIT

Unpacked Size

30.7 kB

Total Files

14

Last publish

Collaborators

  • gk4m