我特意在store.js中打印了typeof rootReducer,打印结果是函数,但是为什么却报了这个错?
我的store.js:
import { createStore } from 'redux'
import rootReducer from './reducer';
const initialState = {};
console.log(typeof rootReducer)
const store = createStore(
rootReducer,
initialState,
window.devToolsExtension ? window.devToolsExtension : f=>f
);
export default store
我的reducer.js:
import { combineReducers } from 'redux';
import { music } from './redux/player.redux';
const rootReducer = combineReducers({
music
});
export default rootReducer
我的app.js:
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import store from './store'
import Router from './router'
class App extends Component {
render() {
const store = store();
return (
<Provider store={store}>
<div className="App">
<Router></Router>
</div>
</Provider>
);
}
}
export default App;
谢邀!
首先恭喜您已经解决了该问题!
白天忙于nextjs + react + 。。。 重构项目,没来得及看!真是抱歉!该问题其实我们看一下createStore的源码就知道了!