https://github.com/michaeljscript/next-restore-scroll-position
Restore scroll position using NextJS
https://github.com/michaeljscript/next-restore-scroll-position
Last synced: 6 months ago
JSON representation
Restore scroll position using NextJS
- Host: GitHub
- URL: https://github.com/michaeljscript/next-restore-scroll-position
- Owner: michaeljscript
- Created: 2023-04-27T07:32:59.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-02T18:31:35.000Z (over 2 years ago)
- Last Synced: 2024-04-29T07:42:17.269Z (almost 2 years ago)
- Language: TypeScript
- Size: 39.1 KB
- Stars: 12
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Restore scroll position in NextJS
Restores scroll position when navigating back and forth in NextJS.
## Installation
```
yarn add next-restore-scroll-position
```
```
npm i next-restore-scroll-position
```
## Usage
```js
import { useScrollRestoration } from 'next-restore-scroll-position';
function App() { // This needs to be NextJS App Component
const router = useRouter();
useScrollRestoration(router);
}
```
**You can also disable the scroll restoration by passing `enabled` property**
```js
import { useScrollRestoration } from 'next-restore-scroll-position';
function App() { // This needs to be NextJS App Component
const router = useRouter();
useScrollRestoration(router, {enabled: false});
}
```
## Peer dependencies
- React 16 or up
- Next 13