Redux Practice Example 2
Creating ActionTypes
hoge.types.js export const HogeActionTypes = { HOGE: 'HOGE', };
Creating Actions (for dispatching)
hoge.actions.js import HogeActionTypes from './hoge.types.js'; export const hoge = () => ({ type: CartActionTypes.HOGE, }); or export const hoge = (item) => ({ type: CartActionTypes.HOGE, payload: item, });
Creating Reducer
hoge.reducer.js import { UserActionTypes } from './hoge.types'; const INITIAL_STATE = { hoge: null, blah: [], foo: true }; const hogeReducer = (state = INITIAL_STATE, action) => { switch (action.type) { case HogeActionTypes.HOGE: return { ...state, hoge: action.payload or blah: action.payload or foo: !state.foo }; default: return state; } }; export default hogeReducer;