Created
March 26, 2018 06:36
-
-
Save nukotsuka/8719a7f26b673f8f4d63ecf568bcc9e3 to your computer and use it in GitHub Desktop.
Ruduxの書き方手順
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Redux |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
書く手順
Reducer
src/reducers/tasks.js
initialStateでStoreに保存するStateを決める。combineReducerを用いる。(createStore.jsでまとまる場合は不要(?))Store
src/createStore.js
combineReducerでは分割された子Reducer名と同じキーのstateが使用できる。(ex. state.tasks, state.router)Root
src/ index.js
ProviderでComponentにstoreを紐づける。ConnectedRouterでComponentにhistoryを紐づける。RouteでRoutingを行う。react-router-domのLinkを用いてページ遷移する。react-router-domのSwitchと、react-router-reduxのpushを用いてページ遷移する。ActionCreater
src/actions/taks.js
flux-standard-action規約
thunkを用いた非同期なActionCreaterthunkを用いた複数のActionCreaterをまとめたActionCreaterContainer
src/containers/Ranking.js
mapStateToPropsでstateを受け取り、Componentに渡すものを決める。state.hogeなどはhogeで扱える。mapDispatchToPropsでdispatchを受け取り、importしたActionCreaterを用いてComponentに渡すメソッドを決める。connectでComponentにmapStateToPropsとmapDispatchToPropsを渡す。Component
src/component/TodoApp.js
mapStateToProps,mapDispatchToPropsの中身を引数に取る。PropTypesを用いてpropTypesを設定する。