0
votes

What is the best practice around redux action creator when it comes to calling action creators for 2 different events for a same functionality? Using redux-thunk to dispatch the actions.

E.g. Lets say I have to write an action creator for saving and printing the user name. Which action creator is better between the 2 below and why?

Action Creator 1

export function actionCreator1(actionType) 
{
     switch(actionType) 
     {
           case "save":
                // dispatch
           case "print": 
                // dispach
           default:
     }
}

Action Creator 2

export function actionCreatorSave() 
{
    // dispatch    
}
export function actionCreatorPrint() 
{
    // dispatch    
}
1
actionCreator2. Because it separates the two different actions altogether.Umang Gupta
Down-voter- I would appreciate if you leave a comment for down-voting this question.Rohan Rayarikar

1 Answers

-2
votes

Both are wrong. In redux, action creators don't dispatch actions. They return actions that you dispatch (in React this is preferably within react-redux mapDispatchToProps function).

http://redux.js.org/docs/basics/Actions.html#action-creators mentions this as opposite to flux.

(the exception being async actions)