Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

redux action

import { createActions, handleActions, combineActions } from 'redux-actions';

const defaultState = { counter: 10 };

const { increment, decrement } = createActions({
  INCREMENT: (amount = 1) => ({ amount }),
  DECREMENT: (amount = 1) => ({ amount: -amount })
});

const reducer = handleActions({  
  [combineActions(increment, decrement)]: (state, action) => {
      return { ...state, counter: state.counter + action.payload.amount };
    }
  },
  defaultState
);

export default reducer;
 
PREVIOUS NEXT
Tagged: #redux #action
ADD COMMENT
Topic
Name
8+6 =