警告:支持类型失败:在`Provider`中未指定必需的prop`store`。在提供者

时间:2016-10-21 17:15:40

标签: react-redux

在添加< Provider>之后,我是使用react-redux的初学者到我的代码,

var React = require("react");
var ReactDOM = require("react-dom");
import { Router, Route, IndexRoute, browserHistory } from "react-router";
import { Provider } from "react-redux";

var BlogApp = require("./components/BlogApp");
var Main = require("./components/Main");
var NewPost = require("./components/NewPost");
var PostDetail = require("./components/PostDetail");
var Login = require("./components/Login");
var Signup = require("./components/Signup");

import { store } from "./store/store";

ReactDOM.render((
  **<Provider store={store}>**
    <Router history={browserHistory}>
      <Route path="/blog" component={BlogApp}>
        <IndexRoute component={Main} />
        <Route path="newpost" component={NewPost} />
        <Route path=":postId" component={PostDetail} />
      </Route>
      <Route path="/login" component={Login} />
      <Route path="/signup" component={Signup} />
    </Router>
  **</Provider>**
  ),
  document.getElementById("root")
);

浏览器控制台报告以下两个警告:

  

警告:道具类型失败:store中未指定必需道具Provider。   警告:childContext类型失败:store中未指定必需的子上下文Provider。在提供者

版本信息如下:

  

“反应”:“^ 15.3.2”,       “react-dom”:“^ 15.3.2”,       “react-redux”:“^ 4.4.5”,       “react-router”:“^ 2.8.1”,       “redux”:“^ 3.6.0”,

相关文件:

store.js:

import { createStore } from "redux";

import { blogReducer } from "../reducers/blogReducer";

const store = createStore(blogReducer);

export default store;

blogReducer.js:

import { combineReducers } from "redux";

const state = {
  posts: [
    {
      id: 1,
      title: "test",
      date: "2016.10.17",
      summary: "test"
    }
  ]
};

function posts(state = [], action) {
  // TODO: temporory code
  return state;
}

/* TODO: must using export, if not the browser will report error below
 bundle.js:10988 Uncaught Error: Expected the reducer to be a function.(…) */
export const blogReducer = combineReducers({
  posts: posts
});

export default blogReducer;

我不知道如何解决它,你能给我一个解决方案吗? TKS

1 个答案:

答案 0 :(得分:1)

我的错误,这是因为错误的导入声明: “import {store} from”./ store / store“;” 它应该是“import store from”./ store / store“;”