Skip to content

Error #2: ViewModel not found

This happened because the vmLookup provided for the useViewModel hook was not found in ViewModelStore.

Explanation:

Hook

tsx
const model = useViewModel(YourVM);

Will use ViewModelStore to find your instance of provided YourVM ViewModel.
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.

Potential solution

Create and register your ViewModel using useCreateViewModel hook or withViewModel HOC.

tsx
const model = useCreateViewModel(YourVM);

You can also create and register your ViewModel using the ViewModelStore.attach() method, but then you will need to reproduce the full creation and destruction cycle, which is implemented inside the hook.

Released under the MIT License.