Error #4: View component already wrapped
This happened because the View component passed to withViewModel is already wrapped in observer.
Explanation
withViewModel automatically wraps the View component in observer so it can track observable values from the ViewModel. Wrapping it manually creates a nested observer or memo layer:
tsx
const Component = withViewModel(VM, observer(({ model }: ViewModelProps<VM>) => {
return <div>{model.title}</div>;
}));Potential solution
Pass a plain inline View function to withViewModel:
tsx
const Component = withViewModel(VM, ({ model }) => {
return <div>{model.title}</div>;
});Do not wrap the View component in observer or React.memo before passing it to withViewModel.
🤖 Prompt for LLM agents
Use the following prompt when asking an LLM agent to fix this error:
text
Fix ReactMark Error #4 in the current repository: "View component already wrapped".
Before editing anything, inspect the current repository and confirm that this
error is actually present. Work only inside the current repository; never edit
absolute paths or files in another project. If no affected usage is found,
report that fact and do not create unrelated files.
Investigate the codebase and find the `withViewModel` call that passes a View
component already wrapped in `observer` or `React.memo`. `withViewModel` already
wraps its View component internally, so the View passed to it must be a plain
function component. Remove only the redundant outer `observer`/`React.memo`
wrapper; do not change the ViewModel, observable access, props, rendered markup,
or the `withViewModel` API.
Then:
1. Search for all affected usages and fix every real occurrence, not just the
first one.
2. Preserve TypeScript types and existing component behavior.
3. Add or update a focused regression test only if the confirmed occurrence is
in tested code and the repository's existing test structure supports it. Do
not create a new test file merely because this prompt requests one. The test
should verify that a plain View function can be passed to `withViewModel`
and that the component still reacts to observable ViewModel changes.
4. Run the repository's relevant typecheck, lint, and test commands.
5. Report the files changed, the root cause, and the verification results.
The fix is complete only when no View passed to `withViewModel` is pre-wrapped
with `observer` or `React.memo`, and the relevant checks pass.