Open History to see the last commit
1import { queryOptions } from '@tanstack/solid-query'
2import axios from 'redaxios'
3β
4export type User = {
5 id: number
6 name: string
7 email: string
8}
9β
10export const DEPLOY_URL = 'http://localhost:3000'
11β
12export const usersQueryOptions = () =>
13 queryOptions({
14 queryKey: ['users'],
15 queryFn: () =>
16 axios
17 .get<Array<User>>(DEPLOY_URL + '/api/users')
18 .then((r) => r.data)
19 .catch(() => {
20 throw new Error('Failed to fetch users')
21 }),
22 })
23β
24export const userQueryOptions = (id: string) =>
25 queryOptions({
26 queryKey: ['users', id],
27 queryFn: () =>
28 axios
29 .get<User>(DEPLOY_URL + '/api/users/' + id)
30 .then((r) => r.data)
31 .catch(() => {
32 throw new Error('Failed to fetch user')
33 }),
34 })