Last active
May 3, 2018 05:17
-
-
Save masa7351/936559ebfc7ea3f02e54232cb074dbc6 to your computer and use it in GitHub Desktop.
Reducerのオーソドックスな書き方
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
import { createStore } from 'redux'; | |
import rootReducer from '../reducers'; | |
export default function configureStore(initialState) { | |
const store = createStore( | |
rootReducer, | |
initialState, | |
); | |
return store; | |
} |
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
import * as types from '../constants/ActionTypes'; | |
const initialState = { | |
value: 0, | |
}; | |
export default function counter(state = initialState, action) { | |
switch (action.type) { | |
case types.INCREMENT: | |
return { value: state.value + 1 }; | |
case types.DECREMENT: | |
return { value: state.value - 1 }; | |
default: | |
return state; | |
} | |
} |
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
import { combineReducers } from 'redux'; | |
import counter from './counter'; | |
const rootReducer = combineReducers({ | |
counter, | |
}); | |
export default rootReducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment