You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Class wrapper for [@tanstack-query/core queries](https://tanstack.com/query/latest/docs/framework/react/guides/queries) with MobX reactivity
26
+
27
+
#### Usage
28
+
29
+
Create an instance of MobxQuery with [`queryKey`](https://tanstack.com/query/latest/docs/framework/react/guides/query-keys) and [`queryFn`](https://tanstack.com/query/latest/docs/framework/react/guides/query-functions) parameters
30
+
```ts
31
+
const query =newMobxQuery({
32
+
queryClient,
33
+
abortSignal, // Helps you to automatically clean up query
34
+
queryKey: ['pets'],
35
+
queryFn: async ({ signal, queryKey }) => {
36
+
const response =awaitpetsApi.fetchPets({ signal });
37
+
returnresponse.data;
38
+
},
39
+
});
40
+
```
41
+
42
+
### Features
43
+
44
+
#### `enableOnDemand` option
45
+
Query will be disabled until you request result for this query
46
+
Example:
47
+
```ts
48
+
const query =newMobxQuery({
49
+
//...
50
+
enableOnDemand: true
51
+
});
52
+
// happens nothing
53
+
query.result.data; // from this code line query starts fetching data
54
+
```
55
+
56
+
#### dynamic `options`
57
+
Options which can be dynamically updated for this query
Update options for query (Uses [QueryObserver](https://tanstack.com/query/latest/docs/reference/QueriesObserver).setOptions)
98
+
99
+
#### hook `onDone()`
100
+
101
+
Subscribe when query has been successfully fetched data
102
+
103
+
#### hook `onError()`
104
+
105
+
Subscribe when query has been failed fetched data
106
+
107
+
#### method `invalidate()`
108
+
109
+
Invalidate current query (Uses [queryClient.invalidateQueries](https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientinvalidatequeries))
110
+
111
+
#### method `reset()`
112
+
113
+
Reset current query (Uses [queryClient.resetQueries](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientresetqueries))
114
+
115
+
#### method `setData()`
116
+
117
+
Set data for current query (Uses [queryClient.setQueryData](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientsetquerydata))
118
+
119
+
#### property `isResultRequsted`
120
+
Any time when you trying to get access to `result` property this field sets as `true`
121
+
This field is needed for `enableOnDemand` option
122
+
This property if **observable**
123
+
124
+
#### property `result`
125
+
126
+
**Observable** query result (The same as returns the [`useQuery` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery))
127
+
128
+
129
+
130
+
### About `enabled`
131
+
All queries are `enabled` (docs can be found [here](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery)) by default, but you can set `enabled` as `false` or use dynamic value like `({ queryKey }) => !!queryKey[1]`
132
+
You can use `update` method to update value for this property or use dynamic options construction (`options: () => ({ enabled: !!this.observableValue })`)
Class wrapper for [@tanstack-query/core mutations](https://tanstack.com/query/latest/docs/framework/react/guides/mutations) with MobX reactivity
184
+
185
+
#### Usage
186
+
187
+
Create an instance of MobxMutation with [`mutationFn`](https://tanstack.com/query/latest/docs/framework/react/guides/mutations) parameter
188
+
```ts
189
+
const mutation =newMobxMutation({
190
+
queryClient,
191
+
abortSignal, // Helps you to automatically clean up mutation
192
+
mutationFn: async ({ signal, queryKey }) => {
193
+
const response =awaitpetsApi.createPet({ name: 'Fluffy' }, { signal });
194
+
returnresponse.data;
195
+
},
196
+
});
197
+
```
198
+
199
+
### Features
200
+
201
+
### method `mutate(variables, options?)`
202
+
203
+
Runs the mutation. (Works the as `mutate` function in [`useMutation` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation))
204
+
205
+
#### hook `onDone()`
206
+
207
+
Subscribe when mutation has been successfully finished
208
+
209
+
#### hook `onError()`
210
+
211
+
Subscribe when mutation has been finished with failure
212
+
213
+
#### method `reset()`
214
+
215
+
Reset current mutation
216
+
217
+
#### property `result`
218
+
219
+
**Observable** mutation result (The same as returns the [`useMutation` hook](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation))
0 commit comments