Skip to content

Commit 17ec2ba

Browse files
Add server usage section for user profile query
Added server usage example for user profile query.
1 parent 1ea9b56 commit 17ec2ba

File tree

1 file changed

+19
-0
lines changed
  • src/routes/solid-router/reference/data-apis

1 file changed

+19
-0
lines changed

src/routes/solid-router/reference/data-apis/query.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,22 @@ const getUserProfileQuery = query(async (userId: string) => {
101101
return json;
102102
}, "userProfile");
103103
```
104+
105+
### Server usage
106+
```tsx
107+
import { query } from "@solidjs/router";
108+
109+
const getUserProfileQuery = query(async (userId: string) => {
110+
"use server";
111+
112+
const response = await fetch(
113+
`https://api.example.com/users/${encodeURIComponent(userId)}`
114+
);
115+
const json = await response.json();
116+
117+
if (!response.ok) {
118+
throw new Error(json?.message ?? "Failed to load user profile.");
119+
}
120+
121+
return json;
122+
}, "userProfile");

0 commit comments

Comments
 (0)