Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 找不到“;储存;,即使根被包装在提供程序中_Reactjs_Redux_Server Side Rendering - Fatal编程技术网

Reactjs 找不到“;储存;,即使根被包装在提供程序中

Reactjs 找不到“;储存;,即使根被包装在提供程序中,reactjs,redux,server-side-rendering,Reactjs,Redux,Server Side Rendering,我有一个SSR react redux应用程序。其中我有一个主index.js文件,包括App组件包装在Provider中 但是如果我尝试在应用程序组件中使用connect,它会抛出以下错误: Uncaught Invariant Violation: Could not find "store" in the context of "Connect(App)" 我已经检查了这些解决方案,没有一个与我相关 //index.js 从“React”导入React; 从'react redux

我有一个SSR react redux应用程序。其中我有一个主index.js文件,包括
App
组件包装在
Provider

但是如果我尝试在
应用程序
组件中使用connect,它会抛出以下错误:

Uncaught Invariant Violation: Could not find "store" in the context of "Connect(App)"
我已经检查了这些解决方案,没有一个与我相关

//index.js
从“React”导入React;
从'react redux'导入{Provider};
从“./App”导入应用程序;
从“/store/configureStore”导入configureStore;
const store=configureStore();
常量应用=()=>(
);
导出默认应用程序;
//App.js
从“React”导入React,{Component}
从“react redux”导入{connect}
类应用程序扩展组件{
render(){
返回(
...
);
}
};
常量mapStateToProps=状态=>{
返回状态;
};
导出默认连接(mapStateToProps,{})(应用程序);
//configureStore.js
从“redux”导入{createStore、applyMiddleware、compose、combinereducer};
从“redux thunk”导入thunk;
从“./login/reducer.js”导入登录名;
常量配置存储=()=>{
const rootReducer=combinereducer({
登录
});
康斯特康塞恩汉斯酒店=
process.env.NODE_env!=='production'和&typeof window==='object'和&window.\uuuuu REDUX\u DEVTOOLS\u EXTENSION\u COMPOSE__
?窗口。\uuuuRedux\uDevTools\uExtension\uCompose__
:撰写;
conststore=createStore(rootReducer,{},composeEnhancers(applyMiddleware(thunk));
退货店;
};
导出默认配置存储;
//登录/reducer.js
const initialState={user:{};
const currentUser=(状态=初始状态,操作)=>{
const{type,payload}=action;
开关(类型){
默认值:{
返回状态;
}
}
};
导出默认的currentUser;
以下是来自浏览器控制台的完整错误

Uncaught Invariant Violation: Could not find "store" in the context of "Connect(App)". 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(App) in connect options.
    at invariant (http://localhost:3000/bundle.js:146050:15)
    at Connect.renderWrappedComponent (http://localhost:3000/bundle.js:51859:58)
    at Connect.indirectRenderWrappedComponent (http://localhost:3000/bundle.js:51855:21)
    at updateContextConsumer (http://localhost:3000/bundle.js:70185:938)
    at beginWork (http://localhost:3000/bundle.js:70212:2189)
    at performUnitOfWork (http://localhost:3000/bundle.js:70889:349)
    at workLoop (http://localhost:3000/bundle.js:70896:45)
    at HTMLUnknownElement.callCallback (http://localhost:3000/bundle.js:67381:102)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/bundle.js:67401:45)
    at invokeGuardedCallback (http://localhost:3000/bundle.js:67417:126)
invariant @ bundle.js:146050
renderWrappedComponent @ bundle.js:51859
indirectRenderWrappedComponent @ bundle.js:51855
updateContextConsumer @ bundle.js:70185
beginWork @ bundle.js:70212
performUnitOfWork @ bundle.js:70889
workLoop @ bundle.js:70896
callCallback @ bundle.js:67381
invokeGuardedCallbackDev @ bundle.js:67401
invokeGuardedCallback @ bundle.js:67417
replayUnitOfWork @ bundle.js:70757
renderRoot @ bundle.js:70918
performWorkOnRoot @ bundle.js:71100
performWork @ bundle.js:71082
performSyncWork @ bundle.js:71080
requestWork @ bundle.js:71056
scheduleWork @ bundle.js:71002
scheduleRootUpdate @ bundle.js:71138
updateContainerAtExpirationTime @ bundle.js:71139
updateContainer @ bundle.js:71139
ReactRoot.render @ bundle.js:71169
(anonymous) @ bundle.js:71182
unbatchedUpdates @ bundle.js:71126
legacyRenderSubtreeIntoContainer @ bundle.js:71182
hydrate @ bundle.js:71185
(anonymous) @ bundle.js:57511
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:52705
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:63
(anonymous) @ bundle.js:66
bundle.js:67495 Warning: Did not expect server HTML to contain a <div> in <div>.
warningWithoutStack @ bundle.js:67495
warnForDeletedHydratableElement @ bundle.js:69163
didNotHydrateContainerInstance @ bundle.js:69265
deleteHydratableInstance @ bundle.js:69882
popHydrationState @ bundle.js:69912
completeWork @ bundle.js:70494
completeUnitOfWork @ bundle.js:70849
performUnitOfWork @ bundle.js:70895
workLoop @ bundle.js:70896
renderRoot @ bundle.js:70911
performWorkOnRoot @ bundle.js:71100
performWork @ bundle.js:71082
performSyncWork @ bundle.js:71080
requestWork @ bundle.js:71056
scheduleWork @ bundle.js:71002
scheduleRootUpdate @ bundle.js:71138
updateContainerAtExpirationTime @ bundle.js:71139
updateContainer @ bundle.js:71139
ReactRoot.render @ bundle.js:71169
(anonymous) @ bundle.js:71182
unbatchedUpdates @ bundle.js:71126
legacyRenderSubtreeIntoContainer @ bundle.js:71182
hydrate @ bundle.js:71185
(anonymous) @ bundle.js:57511
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:52705
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:63
(anonymous) @ bundle.js:66
bundle.js:70552 The above error occurred in the <Context.Consumer> component:
    in Connect(App)
    in Router (created by BrowserRouter)
    in BrowserRouter
未捕获不变冲突:在“连接(应用)”上下文中找不到“存储”。将根组件包装在中,或在“连接选项”中将自定义的React上下文提供程序传递给和相应的React上下文使用者以进行连接(应用程序)。
at不变量(http://localhost:3000/bundle.js:146050:15)
在Connect.RenderRappedComponent处(http://localhost:3000/bundle.js:51859:58)
在Connect.IndirectRenderRappedComponent处(http://localhost:3000/bundle.js:51855:21)
在updateContextConsumer(http://localhost:3000/bundle.js:70185:938)
开始工作时(http://localhost:3000/bundle.js:70212:2189)
在工作中(http://localhost:3000/bundle.js:70889:349)
在workLoop上(http://localhost:3000/bundle.js:70896:45)
在HtmlUnknowneElement.callCallback(http://localhost:3000/bundle.js:67381:102)
在Object.invokeGuardedCallbackDev(http://localhost:3000/bundle.js:67401:45)
在invokeGuardedCallback(http://localhost:3000/bundle.js:67417:126)
不变@bundle.js:146050
RenderRappedComponent@bundle.js:51859
indirectRenderRappedComponent@bundle.js:51855
updateContextConsumer@bundle.js:70185
beginWork@bundle.js:70212
performUnitOfWork@bundle.js:70889
workLoop@bundle.js:70896
callCallback@bundle.js:67381
invokeGuardedCallbackDev@bundle.js:67401
invokeGuardedCallback@bundle.js:67417
replayUnitOfWork@bundle.js:70757
renderRoot@bundle.js:70918
performworkroot@bundle.js:71100
performWork@bundle.js:71082
performSyncWork@bundle.js:71080
requestWork@bundle.js:71056
scheduleWork@bundle.js:71002
scheduleRootUpdate@bundle.js:71138
updateContainerExpirationTime@bundle.js:71139
updateContainer@bundle.js:71139
ReactRoot.render@bundle.js:71169
(匿名)@bundle.js:71182
unbatchedUpdates@bundle.js:71126
legacyRenderSubtreeIntoContainer@bundle.js:71182
水合物@bundle.js:71185
(匿名)@bundle.js:57511
__webpack_require__@bundle.js:20
(匿名)@bundle.js:52705
__webpack_require__@bundle.js:20
(匿名)@bundle.js:63
(匿名)@bundle.js:66
bundle.js:67495警告:不希望服务器HTML中包含。
warningWithoutStack@bundle.js:67495
warnForDeletedHydratableElement@bundle.js:69163
didNotHydrateContainerInstance@bundle.js:69265
deleteAbleInstance@bundle.js:69882
PopHydreationState@bundle.js:69912
completeWork@bundle.js:70494
completeUnitOfWork@bundle.js:70849
performUnitOfWork@bundle.js:70895
workLoop@bundle.js:70896
renderRoot@bundle.js:70911
performworkroot@bundle.js:71100
performWork@bundle.js:71082
performSyncWork@bundle.js:71080
requestWork@bundle.js:71056
scheduleWork@bundle.js:71002
scheduleRootUpdate@bundle.js:71138
updateContainerExpirationTime@bundle.js:71139
updateContainer@bundle.js:71139
ReactRoot.render@bundle.js:71169
(匿名)@bundle.js:71182
unbatchedUpdates@bundle.js:71126
legacyRenderSubtreeIntoContainer@bundle.js:71182
水合物@bundle.js:71185
(匿名)@bundle.js:57511
__webpack_require__@bundle.js:20
(匿名)@bundle.js:52705
__webpack_require__@bundle.js:20
(匿名)@bundle.js:63
(匿名)@bundle.js:66
bundle.js:70552组件中发生上述错误:
in Connect(应用程序)
路由器中(由BrowserRouter创建)
在浏览器路由器中

从堆栈跟踪中,似乎您正在渲染
应用程序。但是,
App
由一个
提供者
包装在您正在创建的名为
App
的新组件中。因此,当您尝试渲染
App
时,react-redux正确地让您知道
App
没有与其关联的
存储

例如,您应该这样写:

const MyAppWithStore = () => (
  <Provider store={store}>
    <App />
  </Provider>
);

ReactDOM.render(<MyAppWithStore />, document.getElementById('root'));
constmyappwithstore=()=>(
);
ReactDOM.render(,document.getElementById('root'));

在您发布的代码中,我看不到您实际呈现根组件的地方,因此上面只是一个需要修改的示例。

也许您也可以发布configureStore()的代码。@ClintonChau更新了问题,请立即检查。谢谢