【发布时间】:2019-10-20 09:48:41
【问题描述】:
我是原生反应新手,我正在尝试在我的应用程序中实现 Redux。使用 react-redux 中的连接函数时反应原生抛出错误,如下所示。
export default connect()(MyComponent);
我检查了所有 3 个选项,我没有破坏任何选项:
- 您的 React 和渲染器版本可能不匹配(例如 React DOM)
- 您可能违反了 Hooks 规则(不确定)
- 您可能在同一个应用中拥有多个 React 副本
下面列出的依赖版本:
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-native": "0.57.7",
"react-native-elements": "^0.19.1",
"react-native-geocoding": "^0.3.0",
"react-native-gesture-handler": "^1.0.12",
"react-native-maps": "https://github.com/react-community/react-native-maps.git",
"react-native-modal": "^9.0.0",
"react-native-router-flux": "^4.0.6",
"react-native-size-matters": "^0.1.4",
"react-native-super-grid": "^3.0.4",
"react-native-vector-icons": "^4.6.0",
"react-navigation": "^3.0.9",
"react-redux": "^7.0.3",
"redux": "^4.0.1",
"redux-logger": "^3.0.6"
当我删除 connect() 时错误消失。但它阻止了植入 Redux
这是 React Native 中的错误还是我在这里做错了什么?
【问题讨论】:
-
你在使用 react hooks 吗?这是使用 connect 方法的正确方法,所以必须进行其他操作
-
我在 react-native 0.57 上。所以我认为它对我不可用。我对么?您认为还有什么问题?
-
谢尔盖·施瓦格是对的。另外,看看这个答案:stackoverflow.com/a/56210647/5563191
标签: react-native redux react-redux