Search code examples
reactjsreduxreact-reduxredux-thunk

Redux Multiple Types In An Action


Just a quick convention question. I have this code working in a redux action of mine. The code works fine but I am unsure if this is accepted among the community or not. Basically I am passing two dispatches in the same action with the goal of passing two seperate actions and payloads. I was getting an error when I tried to pass two types as an array to one type. But I am not sure if this is the best way to go about it? Or if I should just drop it and have two separate actions all together.

Thank You!

dispatch({
  type: GET_WALLET,
  payload: mnemonic
});
dispatch({
  type: AUTHENTICATION,
  payload: false
});

Solution

  • You can separate it into two action creators and make it more clean

    const getWallet = (mnemonic) => ({ type: GET_WALLET, payload: mnemonic });
    
    const auth = () => ({ type: AUTHENTICATION, payload: false });
    
    dispatch(getWallet(mnemonic));
    dispatch(auth());