我是使用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
中指定。警告:Failed childContext type: Required child contextProvider
中没有指定store
。在供应商
版本信息如下:
"反应":"^ 15.3.2",:"react-dom ^ 15.3.2",:"react-redux ^ 4.4.5",:"react-router ^ 2.8.1发布","终极版":"^ 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;
我不知道如何修理它,你能给我一个解决方案吗?谢谢
我的错误,这是因为错误的import语句:"import {store} from "./store/store";"它应该是"import store from。/store/store";