gpt4 book ai didi

reactjs - 警告 : Failed prop type: The prop `store` is marked as required in `Provider` , 但其值为 `undefined` 。在提供者中

转载 作者:行者123 更新时间:2023-12-03 13:17:12 24 4
gpt4 key购买 nike

如何解决react-redux项目中的此错误 error screenshot警告: Prop 类型失败: Prop storeProvider 中被标记为必需,但其值为 undefined。 在提供者中

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import SignUp from './Components/SignUp'
import SignIn from './Components/SignIn'
import Home from './Components/Home'
import { Router, Route, hashHistory, IndexRoute, browserHistory } from 'react-router';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import {firebaseApp} from './Database/firebaseApp'
import {Provider} from 'react-redux'
import {store} from './Store/Store'
import {logUser} from './Store/Actions'

ReactDOM.render(
<MuiThemeProvider>
<Provider store={store}>
<Router history={browserHistory} >

<Route path="/signup" component={SignUp} ></Route>
<Route path="/signin" component={SignIn} ></Route>
<Route path="/home" component={Home} ></Route>

</Router>
</Provider>
</MuiThemeProvider>
,
document.getElementById('root')
);

//存储下面的代码

import { createStore, applyMiddleware,combineReducers } from 'redux';
import thunk from 'redux-thunk';
import {createLogger} from "redux-logger";
//import logger from 'redux-logger'

//import rootReducer from './Reducers/rootReducer'
import {authReducer} from "./Reducers/authReducer"

const rootReducer = combineReducers({
authReducer
})
const logger = createLogger();

let store = createStore(rootReducer, applyMiddleware(thunk, logger) );

export default store;

最佳答案

store 导出为默认值:export default store;

您需要通过以下方式导入它:import store from './Store/Store'

有两种导出方式:

  • export myVar 必须使用 {}
  • 导入
  • export default myVar 必须在不带 {} 的情况下导入

这对于从文件导出/导入多个变量/函数很有用:

// file.js
export a;
export b;
export default c;

//otherfile.js
import c, { a , b} from './file';

关于reactjs - 警告 : Failed prop type: The prop `store` is marked as required in `Provider` , 但其值为 `undefined` 。在提供者中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43253644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com