Skip to content

Wrap in observer() all view components

If you need to automatically wrap in observer() MobX HOC view components for your ViewModel charged components you can achieve this using:

1. wrapViewsInObserver view model config option

Example:

tsx
import { viewModelsConfig } from "mobx-view-model";

viewModelsConfig.wrapViewsInObserver = true;

2. processViewComponent view model config option

Example:

tsx
import { viewModelsConfig } from "mobx-view-model";

viewModelsConfig.processViewComponent = (component) => {
  if ((component as any).$$typeof !== Symbol.for('react.memo')) {
    return;
  }
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  return component && observer(component);
};

Released under the MIT License.