Skip to content

Other

InferQuery, InferMutation, InferInfiniteQuery types

This types are needed to infer some other types from mutations\configs.

ts
type MyData = InferMutation<typeof myMutation, 'data'>
type MyVariables = InferMutation<typeof myMutation, 'variables'>
type MyConfig = InferMutation<typeof myMutation, 'config'>

MobxQueryConfigFromFn, MobxMutationConfigFromFn, MobxInfiniteQueryConfigFromFn

This types are needed to create configuration types from your functions of your http client

ts
const myApi = {
  createApple: (name: string): Promise<AppleDC> => ... 
}

type Config = MobxMutationConfigFromFn<typeof myApi.createApple>

using keyword

MobxQuery, MobxInfiniteQuery, MobxMutation supports out-of-box using keyword.

In your project you need to install babel plugin @babel/plugin-proposal-explicit-resource-management to add this support.

How it looks:

ts
import { createQuery } from "mobx-tanstack-query/preset";

class DataModel {
  async getData() {
    using query = createQuery(() => yourApi.getData(), { queryKey: ['data']});
    await when(() => !query.isLoading);
    return query.result.data!;
  }
}

const dataModel = new DataModel();
const data = await dataModel.getData();
// after call getData() created MobxQuery
// will be destroyed

Released under the MIT License.