|
1
|
# Basic Usage |
|
2
|
|
|
3
|
Always prioritize using a supported framework over using the generated SDK |
|
4
|
directly. Supported frameworks simplify the developer experience and help ensure |
|
5
|
best practices are followed. |
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
### React |
|
11
|
For each operation, there is a wrapper hook that can be used to call the operation. |
|
12
|
|
|
13
|
Here are all of the hooks that get generated: |
|
14
|
```ts |
|
15
|
import { useCreateCategory, useUpsertCategory, useDeleteCategory, useUpdateCategory, useGetCategory, useListCategories, useCreateDevice, useUpsertDevice, useDeleteDevice, useUpdateDevice } from '@dataconnect/generated/react'; |
|
16
|
// The types of these hooks are available in react/index.d.ts |
|
17
|
|
|
18
|
const { data, isPending, isSuccess, isError, error } = useCreateCategory(); |
|
19
|
|
|
20
|
const { data, isPending, isSuccess, isError, error } = useUpsertCategory(upsertCategoryVars); |
|
21
|
|
|
22
|
const { data, isPending, isSuccess, isError, error } = useDeleteCategory(deleteCategoryVars); |
|
23
|
|
|
24
|
const { data, isPending, isSuccess, isError, error } = useUpdateCategory(updateCategoryVars); |
|
25
|
|
|
26
|
const { data, isPending, isSuccess, isError, error } = useGetCategory(getCategoryVars); |
|
27
|
|
|
28
|
const { data, isPending, isSuccess, isError, error } = useListCategories(); |
|
29
|
|
|
30
|
const { data, isPending, isSuccess, isError, error } = useCreateDevice(); |
|
31
|
|
|
32
|
const { data, isPending, isSuccess, isError, error } = useUpsertDevice(upsertDeviceVars); |
|
33
|
|
|
34
|
const { data, isPending, isSuccess, isError, error } = useDeleteDevice(deleteDeviceVars); |
|
35
|
|
|
36
|
const { data, isPending, isSuccess, isError, error } = useUpdateDevice(updateDeviceVars); |
|
37
|
|
|
38
|
``` |
|
39
|
|
|
40
|
Here's an example from a different generated SDK: |
|
41
|
|
|
42
|
```ts |
|
43
|
import { useListAllMovies } from '@dataconnect/generated/react'; |
|
44
|
|
|
45
|
function MyComponent() { |
|
46
|
const { isLoading, data, error } = useListAllMovies(); |
|
47
|
if(isLoading) { |
|
48
|
return <div>Loading...</div> |
|
49
|
} |
|
50
|
if(error) { |
|
51
|
return <div> An Error Occurred: {error} </div> |
|
52
|
} |
|
53
|
} |
|
54
|
|
|
55
|
// App.tsx |
|
56
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; |
|
57
|
import MyComponent from './my-component'; |
|
58
|
|
|
59
|
function App() { |
|
60
|
const queryClient = new QueryClient(); |
|
61
|
return <QueryClientProvider client={queryClient}> |
|
62
|
<MyComponent /> |
|
63
|
</QueryClientProvider> |
|
64
|
} |
|
65
|
``` |
|
66
|
|
|
67
|
|
|
68
|
|
|
69
|
## Advanced Usage |
|
70
|
If a user is not using a supported framework, they can use the generated SDK directly. |
|
71
|
|
|
72
|
Here's an example of how to use it with the first 5 operations: |
|
73
|
|
|
74
|
```js |
|
75
|
import { createCategory, upsertCategory, deleteCategory, updateCategory, getCategory, listCategories, createDevice, upsertDevice, deleteDevice, updateDevice } from '@dataconnect/generated'; |
|
76
|
|
|
77
|
|
|
78
|
// Operation CreateCategory: |
|
79
|
const { data } = await CreateCategory(dataConnect); |
|
80
|
|
|
81
|
// Operation UpsertCategory: For variables, look at type UpsertCategoryVars in ../index.d.ts |
|
82
|
const { data } = await UpsertCategory(dataConnect, upsertCategoryVars); |
|
83
|
|
|
84
|
// Operation DeleteCategory: For variables, look at type DeleteCategoryVars in ../index.d.ts |
|
85
|
const { data } = await DeleteCategory(dataConnect, deleteCategoryVars); |
|
86
|
|
|
87
|
// Operation UpdateCategory: For variables, look at type UpdateCategoryVars in ../index.d.ts |
|
88
|
const { data } = await UpdateCategory(dataConnect, updateCategoryVars); |
|
89
|
|
|
90
|
// Operation GetCategory: For variables, look at type GetCategoryVars in ../index.d.ts |
|
91
|
const { data } = await GetCategory(dataConnect, getCategoryVars); |
|
92
|
|
|
93
|
// Operation ListCategories: |
|
94
|
const { data } = await ListCategories(dataConnect); |
|
95
|
|
|
96
|
// Operation CreateDevice: |
|
97
|
const { data } = await CreateDevice(dataConnect); |
|
98
|
|
|
99
|
// Operation UpsertDevice: For variables, look at type UpsertDeviceVars in ../index.d.ts |
|
100
|
const { data } = await UpsertDevice(dataConnect, upsertDeviceVars); |
|
101
|
|
|
102
|
// Operation DeleteDevice: For variables, look at type DeleteDeviceVars in ../index.d.ts |
|
103
|
const { data } = await DeleteDevice(dataConnect, deleteDeviceVars); |
|
104
|
|
|
105
|
// Operation UpdateDevice: For variables, look at type UpdateDeviceVars in ../index.d.ts |
|
106
|
const { data } = await UpdateDevice(dataConnect, updateDeviceVars); |
|
107
|
|
|
108
|
|
|
109
|
``` |