无法在“连接(应用)”的上下文或道具中找到“商店”。

时间:2018-06-03 19:46:49

标签: reactjs react-redux

我是React Js的新手。 一切正常,直到我在ReactJs尝试做动作创建者。

我知道还有其他问题(帖子)与标题相关,但是,我找不到解决我的问题。请帮帮我!

这是我的index.js

import 'materialize-css/dist/css/materialize.min.css';
import React from 'react';
import ReactDOM from 'react-dom';
import { provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import reduxThunk from 'redux-thunk';

import App from './components/App';
import reducers from './reducers';
import connect from 'react-redux/lib/connect/connect';

// create reducer
const store = createStore(reducers, {}, applyMiddleware(reduxThunk));

// Render the App in the HTML root element which is inside public foler
ReactDOM.render(
    //Provier is to handle redux store actions
    <provider store = { store }><App/></provider> ,
    document.querySelector('#root')
);

这是我的App.Js

import React,{ Component } from 'react';
import { BrowserRouter, Route} from 'react-router-dom';
import { connect } from 'react-redux';
import * as actions from '../actions';

import Header from './Header';
const dashboard = () => <h2>DashBoard</h2>
const surveyNew = () => <h2>SurveyNew</h2>
const landing = () => <h2>Landing</h2>

class App extends Component {

    //Call Action Creaters before View is Up
    componentDidMount() {
        this.props.fetchUser();
    }

    render () {
        return (
            <div className="container">
                <BrowserRouter>
                   <div>
                       <Header/>
                       <Route exact path="/" component = {landing} />
                       <Route exact path = "/surveys" component = {dashboard}/>
                       <Route path = "/surveys/new" component = {surveyNew} />
                   </div>
                </BrowserRouter>
            </div>
        );
    }
};

export default connect(null, actions)(App);

任何帮助将不胜感激,先生。谢谢

1 个答案:

答案 0 :(得分:0)

在“提供者”中有一个大写“p”。试试这样:

import { Provider } from 'react-redux';
...
<Provider store={store}><App/></Provider> ,