如何在单回购中使用反应-冗余连接



我正在向expo-react本机日历应用程序添加redux,该应用程序使用monoreo中共享的组件。

以下是基本目录结构:

app/
web/
Day.web.js
shared/
DayComponent.js
mobile/
App.js
Day.native.js

这是一个很大的简化,但基本上,我的web和移动应用程序称为shared/DayComponent,其中包含许多常见的业务逻辑,它调用web/或mobile/Day.js组件(其中包含纯视图逻辑(。

当我试图在shared/DayComponent.js中运行react redux的connect时,我得到了以下错误:


Error: Could not find "store" in the context of "Connect(App)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(App) in connect options.

通过试错发现了一个解决方案,没有找到关于这个主题的文章或教程。

出于我不完全理解的原因,connect不希望从子模块(在本例中为mobile(主目录之外的模块调用。

在移动目录中,我制作了一个名为connect.js的文件,除了之外什么都没有

import {connect} from 'react-redux'
export default function mobileConnect(...args){
return connect(...args)
}

然后,我没有直接从shared/DayComponent.js内部导入,而是从该文件导入了connect

最新更新