redux - 在“连接(组件)”的上下文中找不到“商店”,尽管传递了提供者和上下文
问题描述
在 React 应用程序中使用 Redux 时,许多其他问题Could not find "store" in the context of...
通过提醒应该将容器组件包装在提供程序或根组件中,或者将特定上下文作为选项传递给connect
. 我正在做所有这一切,它仅在我单独包装容器组件时才有效......而我希望提供者包装根组件。问题是什么?
版本
react: 16.13.1
redux: 4.0.5
react-redux: 7.2.0
索引.jsx
const store = createStore(reducer, state);
const context = React.createContext(undefined);
render(
<Provider store={store} context={context}>
<App />
</Provider>,
document.getElementById("app")
);
ContainerComponent.jsx呈现在App
组件内部的某处。
export const ContainerComponent = connect(
mapStateToProps,
mapDispatchToProps,
null,
{ context }
)(MyComponent);
错误
Uncaught Error: Could not find "store" in the context
of "Connect(MyComponent)". 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(MyComponent) in connect options.
=> 这一切都完成了!
解决方案
The custom context parameters are only intended for very rare use cases. You shouldn't use it normally.
Remove that code.
推荐阅读
- python - 在 Python 中写入 Excel 文件
- mysql - MySQL根据子表状态条件检查创建视图
- flutter - 每次 TextFormField 更改时打印任何值
- python - ImportError:无法导入名称“异步上下文管理器”
- flutter - 向左滑动小部件
- react-native - 当我运行 npx react-native run-android 命令时,它给了我以下错误
- html - 页脚格式问题 - 将页脚直接放在内容下方
- reactjs - 如何从 axios get() 响应中将数据分配给变量
- reactjs - 如何使用 TypeScript 实现 React Hook Form 智能表单组件
- android - 通知滑动时“onNotificationRemoved”不起作用