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

1.0.2 • Public • Published

react-scroll-position

ScrollPosition HOC which remembers attached node scroll position and restores it.

Installation

npm install --save react-scroll-position

Usage

import React, { Component} from 'react'
import ScrollPosition from 'react-scroll-position'
 
const RememberMyScroll = ({ children }) => (
  <ScrollPosition scrollKey="my-scroll">
    {
      ({ attachScrollNode, getScroll, getScrollNode, setScroll }) =>
        <div ref={attachScrollNode}>
          {children}
        </div>
    }
  </ScrollPosition>
)

ScrollPosition HOC uses children as function and returns functions which can be used to manipulate the scrolling.

attachScrollNode

Expects HTMLElement node.

getScroll

Gets attached node x and y scroll positions.

getScrollNode

Gets attached HTMLElement node.

setScroll

Sets attached node x and y scroll positions.

License

MIT

Package Sidebar

Install

npm i react-scroll-position

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

3.17 kB

Total Files

4

Last publish

Collaborators

  • bonnevoyager