简体   繁体   中英

_redux_redux_store__WEBPACK_IMPORTED_MODULE_2___default.a.getState is not a function

I have searched so many but could'nt find answer on this bug please can you help.

_redux_redux_store__WEBPACK_IMPORTED_MODULE_2___default.a.getState is not a function

This is my redux store

import {combineReducers, createStore} from "redux";
import profileReducer from "./profile-reduce";
import dialogsReducer from "./dialogs-reduce";
import sidebarReducer from "./sidebar-reduce";

let reducers = combineReducers({
    profilePage: profileReducer,
    dialogsPage:dialogsReducer,
    sidebar: sidebarReducer
});

let store = createStore(reducers);

export default store;

This is index.js

import React from 'react';
import * as serviceWorker from './serviceWorker';
import store from "./redux/redux-store"
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import {BrowserRouter} from "react-router-dom";


let rerenderEntireTree = (state)=> {
    ReactDOM.render(
        <BrowserRouter>
            <App state={state} dispatch={store.dispatch.bind(store)} store={store}/>
        </BrowserRouter> ,document.getElementById('root'));
}

rerenderEntireTree(store.getState());

store.subscribe(()=>{
    let state = store.getState();
    rerenderEntireTree(state);
});

serviceWorker.unregister();

In your index.js try doing this

import React from 'react';
import * as serviceWorker from './serviceWorker';
import store from "./redux/redux-store"
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import {BrowserRouter} from "react-router-dom";
import { Provider } from 'react-redux';

    ReactDOM.render(
      <Provider store={store}>
        <BrowserRouter>
          <App />
       </BrowserRouter>
      </Provider>,
      document.getElementById('root')
    );

So I have done it by myself, the problem was in naming files. So needed to name my redux-store to redux-store.jsx and it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM