【发布时间】:2021-09-17 20:18:47
【问题描述】:
我正在尝试从 react-redux (https://www.npmjs.com/package/react-redux) 从 5.x 升级到 7.x,以使用钩子并通过 connect() 函数实现了一些重大更改。它一直给我一个错误,我必须将我的应用程序包装在我已经拥有的提供程序中。
错误:
Uncaught (in promise) Invariant Violation: Could not find "store" in either the context or props of "Connect(DateRangeSelector)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(DateRangeSelector)".
提供者代码:
import React from 'react';
import { Provider } from 'react-redux';
import store from 'scripts/setup';
import FullReactComponent from 'root/FullReactComponent';
const App = () => (
<Provider store={store}>
<FullReactComponent />
</Provider>
);
export default App;
连接代码:
FullReactRootComponent.propTypes = {
bgColor: PropTypes.string.isRequired,
};
export const mapStateToProps = ({ portal }) => ({
bgColor: portal.get('bgColor'),
});
export const mapDispatchToProps = {
fetchEnabledRoutes: actions.fetchEnabledRoutes,
};
export default connect(
mapStateToProps,
mapDispatchToProps,
)(FullReactRootComponent);
有没有人在升级时也遇到过这个问题?连接 API 有变化吗?
编辑:这是一个在两个快照之间未正确调用 Connect 的示例:
5.x:
<Connect(ModalComponent) open={true}>
<ModalAdd />
</Connect(ModalComponent)>
7.x:
<ModalComponent
open={true}
/>
【问题讨论】:
-
此处列出了 v6 中的重大更改:github.com/reduxjs/react-redux/releases/tag/v6.0.0。同样,对于 v7:github.com/reduxjs/react-redux/releases/tag/v7.0.1
-
但是代码对我来说看起来不错,损坏的部分应该在其他地方。
-
是的,我阅读了发行说明,从 5.x 开始,它似乎没有中断,因为 6.x 中主要的 thrash 删除了移动商店的能力。
-
您是否不小心在应用程序中拥有多个版本的 React-Redux?
-
当@markerikson 来调试你的redux 问题时,你知道你会得到很好的建议。
标签: javascript reactjs redux react-redux