Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/routes/solid-router/reference/data-apis/query.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,22 @@ const getUserProfileQuery = query(async (userId: string) => {
return json;
}, "userProfile");
```

### Server usage
```tsx
import { query } from "@solidjs/router";

const getUserProfileQuery = query(async (userId: string) => {
"use server";

const response = await fetch(
`https://api.example.com/users/${encodeURIComponent(userId)}`
);
const json = await response.json();

if (!response.ok) {
throw new Error(json?.message ?? "Failed to load user profile.");
}

return json;
}, "userProfile");