You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Minified error `#1`: Active `ViewModel` not found
2
+
3
+
This happened because [`vmLookup`](/api/other/view-model-lookup) for hook [`useViewModel`](/react/api/use-view-model) is not provided and hook trying to lookup active view model using `ActiveViewModelContext` which works only with using [`withViewModel`](/react/api/with-view-model) HOC.
4
+
5
+
6
+
## Explanation:
7
+
8
+
This usage of hook [`useViewModel`](/react/api/use-view-model)
9
+
10
+
```tsx
11
+
const model =useViewModel<YourVM>();
12
+
```
13
+
14
+
Will use `ActiveViewModelContext` which exist only with usage [`withViewModel`](/react/api/with-view-model) HOC.
15
+
16
+
Also this can be happened if you are trying to get access to active `ViewModel` which is not exist in current React render tree:
17
+
18
+
```tsx
19
+
<Component1>
20
+
<ComponentAChild1>
21
+
<Component>
22
+
useViewModel<YourVM>()
23
+
</Component>
24
+
</ComponentAChild1>
25
+
<YourVMComponent /> - this provide active `ViewModel` (withViewModel)
26
+
</Component1>
27
+
```
28
+
29
+
## Potential solution
30
+
31
+
The potential solution to this problem is to pass the [`vmLookup`](/api/other/view-model-lookup) to the hook [`withViewModel`](/react/api/with-view-model)
32
+
33
+
```tsx
34
+
const model = useViewModel(YourVM);
35
+
const model = useViewModel('idofyourvm');
36
+
```
37
+
38
+
Or use `useViewModel<YourVM>()` with correct provided active `ViewModel` React render tree:
39
+
40
+
```tsx
41
+
<YourVMComponent> - this provide active `ViewModel` (withViewModel)
This happened because your [`vmLookup`](/api/other/view-model-lookup) provided for hook [`useViewModel`](/react/api/use-view-model) is not found in [`ViewModelStore`](/api/view-model-store/overview).
4
+
5
+
6
+
## Explanation:
7
+
8
+
Hook
9
+
10
+
```tsx
11
+
const model =useViewModel(YourVM);
12
+
```
13
+
14
+
Will use [`ViewModelStore`](/api/view-model-store/overview) to find your instance of provided `YourVM`[`ViewModel`](/api/view-models/overview).
15
+
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.
16
+
17
+
## Potential solution
18
+
19
+
Create and register your `ViewModel` using [`useCreateViewModel`](/react/api/use-create-view-model) hook or [`withViewModel`](/react/api/with-view-model) HOC.
20
+
21
+
```tsx
22
+
const model =useCreateViewModel(YourVM);
23
+
```
24
+
25
+
Also you can create and register your `ViewModel` using [ViewModelStore.attach() method](/api/view-model-store/interface#attach-viewmodel), but then you will need to completely reproduce the cycle of creating and destroying the `ViewModel`, which is described in the original code of the hook.
'This happens 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.\n'+
46
+
'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.\n'+
47
47
'Please provide "vmLookup" (first argument for "useViewModel" hook) or use "withViewModel" HOC.\n'+
0 commit comments