问题描述
我试图在React中使用Mobx的viewmodel utils。
我的商店是:
export class CompanyStore extends StoreExt {
@observable
companyDetails: ICompanyDetails = {}
}
当我使用'createviewmodel'函数时,在组件中就像这样:
function CompanyDetails() {
const { companyStore } = useRootStore()
const test = createviewmodel(companyStore.companyDetails);
}
我收到此错误:
Uncaught TypeError: Object(...) is not a function
at new viewmodel (mobx-utils.module.js?1a9d:629)
at createviewmodel (mobx-utils.module.js?1a9d:775)
at CompanyDetails (index.tsx?dbb5:21)
at eval (observer.js?796d:24)
at eval (uSEObserver.js?338c:91)
at trackDerivedFunction (mobx.es6.js?cacc:668)
at Reaction.track (mobx.es6.js?cacc:1705)
at eval (uSEObserver.js?338c:89)
at useQueuedForceUpdateBlock (useQueuedForceUpdate.js?20c5:19)
at uSEObserver (uSEObserver.js?338c:83)
为什么会导致这种情况?
解决方法
好,问题是Mobx与 mobx-utils 软件包之间不兼容。通过将它们匹配到相同的版本,此问题得以解决。