Skip to content

Instantly share code, notes, and snippets.

@masa7351
Last active May 3, 2018 05:05
Show Gist options
  • Save masa7351/371f174aa67d816a9fd581b0975c3060 to your computer and use it in GitHub Desktop.
Save masa7351/371f174aa67d816a9fd581b0975c3060 to your computer and use it in GitHub Desktop.
createReducerを使用したReducerの書き方 - パート1
import { createStore } from 'redux';
import rootReducer from '../reducers';
export default function configureStore(initialState) {
const store = createStore(
rootReducer,
initialState,
);
return store;
}
import * as types from '../constants/ActionTypes';
import { createReducer } from '../modules/helpers';
const initialState = {
value: 0,
};
export default {
counter: createReducer(initialState, {
[types.INCREMENT](state) {
return Object.assign({}, state, {value: state.value + 1});
},
[types.DECREMENT](state) {
return Object.assign({}, state, {value: state.value - 1});
},
}),
};
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