Modern React with Redux #4
- reducerはアプリケーションのstateを返す関数
- keyは任意のもの。valueはhogeReducer(state)
- reducerの役割は2STEP
- STEP1: Reducerをつくること
- STEP2: 実際にアプリケーションと接続すること
- combineReducersがアプリケーションのstateをマッピングする
- Containerはreduxが生成したstateに直接アクセスのできるreact component
- connectはreactとreduxを繋ぐmiddlewareの関数
- mapStateToPropsはstateを引数に持つ関数で、この関数でreturnしたpropsをConatainer内で参照できるのりみたいなモノ
- containersでmapStateToPropsする場合は、componentそれ自身をexport defaultしない。なぜならstateも一緒に渡したいから(export defalut connect(mapStateToProps)(CoponentName)のような書き方をする)
- connect(function)(container)
- mapStateToPropsで返されたpropsはContainer内で使える
- mapDispatchToPropsで定義されたものが呼び出されると、その結果はすべてのReducerに渡される
- actionCreatorはtypeとpayloadの2つのvalueをもつ
- reducerではfreshなオブジェクトを返さなければならない。state.hogeなどをreturnするのはだめ
Section2はReact内でstateを使う、Section3はReduxの公式ドキュメントを解説って感じでしたー(下書き保存していなかった)