在React应用程序中使用Redux时,许多其他问题通过提醒人们应该将容器组件包装在提供程序或根组件中,或将特定上下文作为选项传递给Could not find "store" in the context of...
,从而解决了connect
问题。 react: 16.13.1
redux: 4.0.5
react-redux: 7.2.0
。我正在做所有这一切,并且仅当我单独包装容器组件时才起作用...而我希望提供者包装根组件。有什么问题吗?
版本
const store = createStore(reducer, state);
const context = React.createContext(undefined);
render(
<Provider store={store} context={context}>
<App />
</Provider>,
document.getElementById("app")
);
index.jsx
App
ContainerComponent.jsx 呈现在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.
错误
version: "3"
services:
coreapi:
build:
context: ./theapi
dockerfile: Dockerfile
ports:
- "5000:5000"
sqlserver:
build:
context: ./sqlserver
environment:
- ACCEPT_EULA="Y"
- SA_PASSWORD="Pwd12345!"
ports:
- "11433:1433"
=>一切都完成了!
答案 0 :(得分:0)
自定义上下文参数仅适用于非常罕见的用例。您不应该正常使用它。
删除该代码。