[英]React-Redux & Material UI: Component doesn't pass store to 'connected' child
Duplicated Code Sandbox https://ndg6d.csb.app/重复代码沙箱https://ndg6d.csb.app/
Full Error Uncaught Error: Could not find "store" in the context of "Connect(UploadInternal)". 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(UploadInternal) in connect opt.
完全错误
Uncaught Error: Could not find "store" in the context of "Connect(UploadInternal)". 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(UploadInternal) in connect opt.
Uncaught Error: Could not find "store" in the context of "Connect(UploadInternal)". 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(UploadInternal) in connect opt.
Situation Everything was working correctly, then updated react 15.x to 16.13.x, and react-redux from 5.x to 7.2.x, and now the error above occurs when a connected component is passed as a child to the Dialog
component in Upload.jsx
.情况一切正常,然后将 react 15.x 更新为 16.13.x,并将 react-redux 从 5.x 更新为 7.2.x,现在当连接的组件作为子组件传递给
Upload.jsx
中的Dialog
组件时,会发生上述错误。 Upload.jsx
The store is passed correctly to the child component if it's not nested in Dialog
.如果商店没有嵌套在
Dialog
中,它会正确传递给子组件。 I am using a very old version of Material UI (v0.20.2), but it's package.json
file lists both dependencies react
and react-dom
as ^16.0.0
, so it should be ok.我正在使用一个非常旧版本的 Material UI (v0.20.2),但它是
package.json
文件将依赖关系react
和react-dom
列为^16.0.0
,所以应该没问题。
Add this code to the index.js if you haven't done that:如果您还没有这样做,请将此代码添加到 index.js:
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import rootReducer from "./store/reducers";
const composeEnhances = window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() : f => f;
const store = createStore(rootReducer,compose(applyMiddleware(thunk),composeEnhances));
const app = (
<Provider store={store}>
<App />
</Provider>
);
the reducer index.js file would be like:减速器 index.js 文件如下:
import { combineReducers } from 'redux';
import rootReducer from "../components/app/reducers";
export default combineReducers({
// your reducers here
root: rootReducer,
});
I believe this is caused by an outdated MaterialUI
component that's creating a popover outside the context as mentioned here .我相信这是由过时的
MaterialUI
组件引起的,该组件在此处提到的上下文之外创建了一个弹出框。 The child nested in the MaterialUI
component Dialog
throws the error.嵌套在
MaterialUI
组件Dialog
中的子项会抛出错误。 However, if the child is not nested in Dialog
, then it has access to the store.但是,如果孩子没有嵌套在
Dialog
中,那么它可以访问商店。 This shows that the root, its children, and grandchildren have access to the store, and shows Dialog
causes the breaking boundary in this situation.这表明根、它的子、孙都可以访问存储,并表明
Dialog
在这种情况下导致了边界中断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.