Warning: Failed prop type: The prop `store` is marked as required in `Provider`, but its value is `undefined`. in Provider

断了今生、忘了曾经 提交于 2019-12-18 13:12:13

问题


How to resolve this error in react-redux project error screenshot Warning: Failed prop type: The prop store is marked as required in Provider, but its value is undefined. in Provider

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')
);

//store code below

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;

回答1:


You export store as default: export default store;

You need to import it this way: import store from './Store/Store'

There are two kinds of export:

  • export myVar must be imported with { and }
  • export default myVar must be imported without { and }

This is useful to export/import multiple variables/functions from a file:

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

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


来源:https://stackoverflow.com/questions/43253644/warning-failed-prop-type-the-prop-store-is-marked-as-required-in-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!