【Redux】ReactやるにもAngularやるにもとにかくRedux

【react-router-redux】解決したい。Expected the reducer to be a function(createStore.js)

【react-router-redux】解決したい。Expected the reducer to be a function(createStore.js)

コンソールにExpected the reducer to be a functionが出てお困りの方。createStoreから出ています。

【react-router-redux】解決したい。Expected the reducer to be a function(createStore.js)
【react-router-redux】解決したい。Expected the reducer to be a function(createStore.js)

createStoreのここでfunctionが渡ってくるはずがObjectとかで渡ってきているのだと思います。
わたくしがそうでした。。

reduxが提供するcreateStoreAPIによると

createStore(reducer, [preloadedState], [enhancer])

のシグネチャで、
reducer (Function): A reducing function that returns the next state tree, given the current state tree and an action to handle.

reducerはnextState返すFunctionじゃないとだめ。

なのでもしcreateStoreの引数に{}してたら、
modify this code

[code language="javascript"]
const store = createStore({
appReducer
})
[/code]

to

[code language="javascript"]
const store = createStore(
appReducer
)
[/code]

一旦。エラーは変わるはずです。

 

もしくはimport exportのあたりをObjectでわたし、受け取り、とかその辺かもですね。