Skip to content

Commit

Permalink
Add documentation about lazily evaluating "preserveScroll"
Browse files Browse the repository at this point in the history
  • Loading branch information
reinink committed Jan 2, 2021
1 parent 5adbb52 commit 0047a8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pages/manual-visits.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ When navigating between pages, Inertia mimics default browser behaviour by autom
Inertia.visit(url, { preserveScroll: true })
```

You can also lazily evaluate the `preserveScroll` option based on the response by providing a callback.

```js
Inertia.post('/users', data, {
preserveScroll: (page) => Object.keys(page.props.errors).length,
})
```

For more information, see the [scroll management](/scroll-management) page.

## Partial reloads
Expand Down
10 changes: 9 additions & 1 deletion pages/scroll-management.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ Sometimes it's desirable to prevent the default scroll resetting when making vis
Inertia.visit(url, { preserveScroll: true })
```

This is also possible with [Inertia links](/links) using the `preserve-scroll` attribute.
You can also lazily evaluate the `preserveScroll` option based on the response by providing a callback.

```js
Inertia.post('/users', data, {
preserveScroll: (page) => Object.keys(page.props.errors).length,
})
```

You can also preserve the scroll position with [Inertia links](/links) using the `preserve-scroll` attribute.

<TabbedCodeExamples
examples={[
Expand Down

0 comments on commit 0047a8b

Please sign in to comment.