React.createElement:类型无效——需要一个字符串——提供者不工作

React.createElement: type is invalid -- expected a string - provider doesnt work

我在路由器的某处有问题,这是错误消息 React.createElement:类型无效 -- 需要一个字符串。

关于这个问题我写了每篇文章,但还是没有解决。

我是 React 的初学者,我想从新项目开始。

我的index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { BrowserRouter as Router, Route, IndexRoute } from 'react-router-dom';
import { Provider } from 'redux';
import createBrowserHistory from 'history/createBrowserHistory';

import App from './js/pages/App/App';
import Container from './js/components/Container/Container';

import store from './js/store';

const app = document.getElementById('app');
const newHistory = createBrowserHistory();

ReactDOM.render((
    <Provider store={store}>
        <Router history={newHistory}>
            <Route path="/" component={App}>
                <Route path="/container" component={Container} />
            </Route>
        </Router>
    </Provider>
),
app
);

module.hot.accept();

我的store.js

import {applyMiddleware, createStore} from "redux";

import {createLogger} from "redux-logger";
import thunk from "redux-thunk";
import promise from "redux-promise-middleware";
import {save, load} from "redux-localstorage-simple";


import reducer from "./reducers/index";

var createStoreWithMiddleware = null;
if (process.env.NODE_ENV !== 'production') {
createStoreWithMiddleware
    = applyMiddleware(
    promise(),
    thunk,
    createLogger()
)(createStore);
}
else {
createStoreWithMiddleware
    = applyMiddleware(
    promise(),
    thunk
)(createStore);
}

//const middleware = applyMiddleware(promise(), thunk, createLogger());

const store = createStoreWithMiddleware(
reducer // Loading done here
);
export default store;

我认为这里的某个地方有问题,因为当我删除 Provider 时,我看到了 App 页面。

感谢您的帮助。

Provider 是 React Redux 提供的高阶组件,可让您将 Redux 绑定到 React。

根据 redux 的文档: https://redux.js.org/advanced/usagewithreactrouter

你需要

import { Provider } from 'react-redux'