Minified error #1
: Active ViewModel
not found
This happened because vmLookup
for hook useViewModel
is not provided and hook trying to lookup active view model using ActiveViewModelContext
which works only with using withViewModel
HOC.
Explanation:
This usage of hook useViewModel
tsx
const model = useViewModel<YourVM>();
Will use ActiveViewModelContext
which exist only with usage withViewModel
HOC.
Also this can be happened if you are trying to get access to active ViewModel
which is not exist in current React render tree:
tsx
<Component1>
<ComponentAChild1>
<Component>
useViewModel<YourVM>()
</Component>
</ComponentAChild1>
<YourVMComponent /> - this provide active `ViewModel` (withViewModel)
</Component1>
Potential solution
The potential solution to this problem is to pass the vmLookup
to the hook withViewModel
tsx
const model = useViewModel(YourVM);
const model = useViewModel('idofyourvm');
Or use useViewModel<YourVM>()
with correct provided active ViewModel
React render tree:
tsx
<YourVMComponent> - this provide active `ViewModel` (withViewModel)
<Component1>
<ComponentAChild1>
<Component>
useViewModel<YourVM>()
</Component>
</ComponentAChild1>
</Component1>
</YourVMComponent>