Skip to content

BonneVoyager/react-scroll-position

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Remember and restore React scroll position for html element nodes.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published