Skip to content

Commit 9081f16

Browse files
committed
docs: update shouldRevalidate docs
1 parent 57da40b commit 9081f16

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/start/data/route-object.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,17 @@ export default function Items() {
139139

140140
## `shouldRevalidate`
141141

142-
By default, all routes are revalidated after actions. This function allows a route to opt-out of revalidation for actions that don't affect its data.
142+
Loader data is automatically revalidated after certain events like navigations and form submissions.
143+
144+
This hook enables you to opt in or out of the default revalidation behavior. The default behavior is nuanced to avoid calling loaders unnecessarily.
145+
146+
A route loader is revalidated when:
147+
148+
- its own route params change
149+
- any change to URL search params
150+
- after any actions are called
151+
152+
By defining this function, you opt out of the default behavior completely and can manually control when loader data is revalidated for navigations and form submissions.
143153

144154
```tsx
145155
import type { ShouldRevalidateFunctionArgs } from "react-router";
@@ -159,6 +169,10 @@ createBrowserRouter([
159169
]);
160170
```
161171

172+
[`ShouldRevalidateFunctionArgs` Reference Documentation ↗](https://api.reactrouter.com/v7/interfaces/react_router.ShouldRevalidateFunctionArgs.html)
173+
174+
Please note the default behavior is different in [Framework Mode](../modes).
175+
162176
## `lazy`
163177

164178
Most properties can be lazily imported to reduce the initial bundle size.

docs/start/framework/route-module.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ export default function Root() {
351351

352352
## `shouldRevalidate`
353353

354-
By default, all routes are revalidated after actions. This function allows a route to opt-out of revalidation for actions that don't affect its data.
354+
In framework mode, route loaders are automatically revalidated after all navigations and form submissions (this is different from [Data Mode](../data/route-object#shouldrevalidate)). This enables middleware and loaders to share a request context and optimize in different ways than then they would be in Data Mode.
355+
356+
Defining this function allows you to opt out of revalidation for a route loader for navigations and form submissions.
355357

356358
```tsx
357359
import type { ShouldRevalidateFunctionArgs } from "react-router";
@@ -363,6 +365,8 @@ export function shouldRevalidate(
363365
}
364366
```
365367

368+
[`ShouldRevalidateFunctionArgs` Reference Documentation ↗](https://api.reactrouter.com/v7/interfaces/react_router.ShouldRevalidateFunctionArgs.html)
369+
366370
---
367371

368372
Next: [Rendering Strategies](./rendering)

0 commit comments

Comments
 (0)