---
url: /mobx-view-model/v10/errors/2.md
---
# &#x20;Error `#2`: `ViewModel` not found

This happened because the [`vmLookup`](/api/other/view-model-lookup) provided for the [`useViewModel`](/react/api/use-view-model) hook was not found in [`ViewModelStore`](/api/view-model-store/overview).

## Explanation:

Hook

```tsx
const model = useViewModel(YourVM);
```

Will use [`ViewModelStore`](/api/view-model-store/overview) to find your instance of provided `YourVM` [`ViewModel`](/api/view-models/overview).\
It means that your `ViewModel` is not created yet and not registered in `ViewModelStore`, or you have not declared the creation of this `ViewModel` anywhere.

### HMR (Hot Module Replacement)

This error can also happen during development with HMR. When you edit a `ViewModel` class (add/remove a property, change a method, etc.), HMR replaces it with a new class — but the instance in `ViewModelStore` still belongs to the old one. The lookup can't find it and throws.

## Potential solution

Create and register your `ViewModel` using [`useCreateViewModel`](/react/api/use-create-view-model) hook or [`withViewModel`](/react/api/with-view-model) HOC.

```tsx
const model = useCreateViewModel(YourVM);
```

You can also create and register your `ViewModel` using the [ViewModelStore.attach() method](/api/view-model-store/interface#attach-viewmodel), but then you will need to reproduce the full creation and destruction cycle, which is implemented inside the hook.

### Fixing HMR issues

If the error only appears after editing a `ViewModel` class during development, use the [`mobx-view-model-vite-plugin`](https://github.com/js2me/mobx-view-model-vite-plugin) — it automatically reconciles the old and new constructors on HMR updates so the lookup continues to work without a full page reload.
