-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathuseLoadEntitiesREST.ts
More file actions
41 lines (37 loc) · 919 Bytes
/
useLoadEntitiesREST.ts
File metadata and controls
41 lines (37 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { useQuery } from "react-query";
import { fetchApi } from "./restApi";
interface EntityListResponse {
entities: any[];
pagination: Record<string, any>;
relationships?: Record<string, any[]>;
}
const useLoadEntitiesREST = (project: string) => {
return useQuery(
["entities-rest", project],
() =>
fetchApi<EntityListResponse>("/entities", {
project,
allow_cache: "false",
}),
{
enabled: !!project,
staleTime: 30000,
},
);
};
const useLoadEntityREST = (name: string, project: string) => {
return useQuery(
["entity-rest", name, project],
() =>
fetchApi<any>(`/entities/${encodeURIComponent(name)}`, {
project,
include_relationships: "true",
allow_cache: "false",
}),
{
enabled: !!name && !!project,
staleTime: 30000,
},
);
};
export { useLoadEntitiesREST, useLoadEntityREST };