Skip to content

Commit fd9bf17

Browse files
Move revalidate docs to the Data APIs section (#1206)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 458dbf0 commit fd9bf17

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed

src/middleware/legacy-routes-redirect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ const LEGACY_ROUTES = {
107107

108108
// solid-docs-next moves/new location for old pages/solid api updates
109109
"/reference/jsx-attributes/on-and-oncapture": "/reference/jsx-attributes/on",
110-
110+
111+
"/solid-router/reference/response-helpers/revalidate": "/solid-router/reference/data-apis/revalidate",
111112
} as const;
112113

113114
function isLegacyRoute(path: string): path is keyof typeof LEGACY_ROUTES {

src/routes/solid-router/reference/data-apis/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"create-async.mdx",
77
"create-async-store.mdx",
88
"query.mdx",
9+
"revalidate.mdx",
910
"use-action.mdx",
1011
"use-submission.mdx",
1112
"use-submissions.mdx"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: revalidate
3+
---
4+
5+
The `revalidate` function is used to revalidate queries associated with specified [query keys](/solid-router/reference/data-apis/query#query-keys).
6+
When a [query](/solid-router/reference/data-apis/query) is revalidated, it is executed again, and any references to the associated query data are updated accordingly.
7+
8+
```tsx
9+
import { For } from "solid-js";
10+
import { query, createAsync, revalidate } from "@solidjs/router";
11+
12+
const getPosts = query(async () => {
13+
return await fetch("https://api.com/posts").then((response) =>
14+
response.json()
15+
);
16+
}, "posts");
17+
18+
function Posts() {
19+
const posts = createAsync(() => getPosts());
20+
21+
function refetchPosts() {
22+
revalidate(getPosts.key);
23+
}
24+
25+
return (
26+
<div>
27+
<button onClick={refetchPosts}>Refetch posts</button>
28+
<ul>
29+
<For each={posts()}>{(post) => <li>{post.title}</li>}</For>
30+
</ul>
31+
</div>
32+
);
33+
}
34+
```
35+
36+
## Parameters
37+
38+
- `key`: The query key or an array of query keys to be revalidated.
39+
- `force` (optional): A boolean that indicates whether to delete the existing cached value of the queries.
40+
Note that this cache is solely for de-duplication purposes.
41+
Therefore, deleting the cache only affects de-duplication.
42+
For more information on how `query` works, refer to [the `query` documentation](/solid-router/reference/data-apis/query).
43+
The default value is `true`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"title": "Response helpers",
3-
"pages": ["json.mdx", "redirect.mdx", "reload.mdx", "revalidate.mdx"]
3+
"pages": ["json.mdx", "redirect.mdx", "reload.mdx"]
44
}

src/routes/solid-router/reference/response-helpers/revalidate.mdx

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)