An open API service indexing awesome lists of open source software.

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

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