Skip to content

Commit aed4133

Browse files
committed
docs: add info about using keyword
1 parent 7fbddc1 commit aed4133

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/api/other.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,31 @@ const myApi = {
2323

2424
type Config = MobxMutationConfigFromFn<typeof myApi.createApple>
2525
```
26+
27+
28+
## `using` keyword
29+
30+
`MobxQuery`, `MobxInfiniteQuery`, `MobxMutation` supports out-of-box [`using` keyword](https://github.com/tc39/proposal-explicit-resource-management).
31+
32+
In your project you need to install babel plugin [`@babel/plugin-proposal-explicit-resource-management`](https://www.npmjs.com/package/@babel/plugin-proposal-explicit-resource-management) to add this support.
33+
34+
How it looks:
35+
36+
```ts
37+
import { createQuery } from "mobx-tanstack-query/preset";
38+
39+
class DataModel {
40+
async getData() {
41+
using query = createQuery(() => yourApi.getData(), { queryKey: ['data']});
42+
await when(() => !query.isLoading);
43+
return query.result.data!;
44+
}
45+
}
46+
47+
const dataModel = new DataModel();
48+
const data = await dataModel.getData();
49+
// after call getData() created MobxQuery
50+
// will be destroyed
51+
```
52+
53+

0 commit comments

Comments
 (0)