showing results for - "redux action"
Ryad
17 Apr 2017
1export const UPDATE_PRODUCTS = "UPDATE_PRODUCTS";
2export const UPDATE_CATEGORIES = "UPDATE_CATEGORIES";
3export const UPDATE_CURRENT_CATEGORY = "UPDATE_CURRENT_CATEGORY";
Florencia
18 Jul 2018
1//npm i redux-actions or yarn add redux-actions
2
3// single action creator
4export const incAsyncCreator = createAction("INC");
5export const decAsyncCreator = createAction("DEC");
6
7// single action creator using - single reducer 
8export const incReducer = handleAction(
9  incAsyncCreator,
10  (state, action) => ({
11    ...state,
12    counter: state.counter + 1,
13    success: action.payload.success
14  }),
15  counterState
16);
17
18// single action creator using - single reducer 
19export const decReducer = handleAction(
20  incAsyncCreator,
21  (state, action) => ({
22    ...state,
23    counter: state.counter + 1,
24    success: action.payload.success
25  }),
26  counterState
27);
28
29
30//multiple action creator
31export const { increment, decrement } = createActions({
32  increment: (payload) => ({ ...payload }),
33  decrement: (payload) => ({ ...payload })
34});
35
36// multiple action creator using - multiple reducer 
37export const counterReducer = handleActions(
38  {
39    [increment]: (state, action) => ({
40      ...state,
41      counter: state.counter + 1,
42      success: action.payload.success
43    }),
44    [decrement]: (state, action) => ({
45      ...state,
46      counter: state.counter - 1,
47      success: action.payload.success
48    })
49  },
50  counterState
51);