react-scroll-on-navigate

0.1.3 • Public • Published

React Scroll on Navigate

Scroll to top automatically when the route changes. Works well with React Router and other similar tools.

See the React Router guide for more details.

Usage

Manually, passing in your router's location prop:

import { ScrollToTopOnNavigate } from 'react-scroll-on-navigate';
 
<div className="MyApp">
  <ScrollToTopOnNavigate location={location} />
  ...
</div>

Or, using a decorator if you prefer:

import { ScrollToTopOnNavigate as ScrollToTopWithoutRouter } from 'lsr-lib';
import { withRouter } from 'react-router';
 
const ScrollToTopOnNavigate = withRouter(ScrollToTopWithoutRouter);
 
<div className="MyApp">
  <ScrollToTopOnNavigate />
  ...
</div>

Package Sidebar

Install

npm i react-scroll-on-navigate

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

5.84 kB

Total Files

8

Last publish

Collaborators

  • cooperka