Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-use-sync-scroll

agorf8.9kMIT0.1.0TypeScript support: included

A custom React hook for synchronized DOM element scrolling

react, hook, sync, synchronized, scroll, scrolling, dom, element

readme

useSyncScroll

npm version

A custom React hook for synchronized, proportional, horizontal and/or vertical DOM element scrolling.

DEMO

Install

With npm:

npm install react-use-sync-scroll

With Yarn:

yarn add react-use-sync-scroll

In a browser:

<script src="https://unpkg.com/react-use-sync-scroll/dist/index.js"></script>

Use

The hook accepts two arguments:

  • A ref of refs (at least 2) of elements to synchronize
  • An options object to define whether to synchronize horizontal or vertical scrolling (both default to false)

For example:

import useSyncScroll from 'react-use-sync-scroll';

function SomeComponent() {
  // Make a ref for each element to synchronize
  const ref1 = React.useRef(null);
  const ref2 = React.useRef(null);
  const ref3 = React.useRef(null);

  // Combine them into a single array ref
  const refsRef = React.useRef([ref1, ref2, ref3]);

  // Use the hook
  useSyncScroll(refsRef, { vertical: true, horizontal: false });

  // Render
  return (
    <div>
      <div ref={ref1}>...</div>
      <div ref={ref2}>...</div>
      <div ref={ref3}>...</div>
    </div>
  );
}

License

MIT

Author

Angelos Orfanakos

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

0.1.0 - 2019-10-04

Added

  • TypeScript definitions #5

Changed

  • Run sync logic in window.requestAnimationFrame for smoother scrolling #1
  • Bump eslint-utils from 1.3.1 to 1.4.2 to address security vulnerabilities #6
  • Bump lodash from 4.17.11 to 4.17.15 to address security vulnerabilities #7
  • Improve README.md file text
  • Update demo page for version 0.1.0

Fixed

  • refsRefOk inverted conditional #3

0.0.6 - 2019-06-20

Fixed

  • Add forgotten .current to ref

0.0.5 - 2019-06-20 [YANKED]

Yanked release. Accidental copy of 0.0.4

0.0.4 - 2019-06-20

Added

  • Demo file under docs folder
  • ESLint configuration with eslint-plugin-react-hooks
  • Keywords in package.json
  • npm package version badge in README.md file

Changed

  • Pass refs instead of building them internally
  • Remove use of Array.prototype.keys for IE compatibility
  • Improve README.md file text

0.0.3 - 2019-06-20 [YANKED]

Yanked release. Accidental copy of 0.0.2

0.0.2 - 2019-05-31

Added

  • Use rollup to build dist files

Changed

  • Improve README.md text
  • Improve description in package.json

0.0.1 - 2019-05-30

Added

Initial release.