微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Mobx React-CreateViewModel-错误-对象不是函数

如何解决Mobx React-CreateViewModel-错误-对象不是函数

我试图在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 软件包之间不兼容。通过将它们匹配到相同的版本,此问题得以解决。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。