Skip to content

View Model Lookup ​

ViewModelLookup, vmLookup ​

This type declares what data is needed to find your ViewModel instance in ViewModelStore.

It can be:

Reference to source code type

ViewModelComponentRef<T> ​

Type-only brand used by framework packages so get / useViewModel can infer the concrete ViewModel type from a HOC component reference. Never read at runtime.

Example ​

This example represents a scenario where you are not using the React integration API.

ts
import { ViewModelStoreBase, ViewModelBase } from "mobx-view-model"

const vmStore = new ViewModelStoreBase();

class MyVM extends ViewModelBase {
  constructor() {
    super({ id: '1', payload: {} });
  }
}

const vm = vmStore.define({
  id: '1',
  payload: {},
  VM: MyVM,
});

vmStore.get(vm.id) // instance of MyVM
vmStore.get(MyVM) // instance of MyVM