mardi 28 mai 2019

Is it wrong to call component methods passed as arguments inside of redux actions?

I'm struggling with one task I've been appointed to and the only workaround I found is to call the action argument callback inside the action. Is this a bad idea from a design point of view, because the code itself works and passes numerous tests? The general purpose of this solution is to somehow trigger the component function when a certain logic is being followed.


export function myAction(componentClb: () => void): any {
  return (dispatch: Dispatch<AppStore>): void => {
    someRESTAPIcall()
      .then((condition) => {
        condition
          ? dispatch(anotherActionThatTakesCallbackAsArgument(componentClb))
          : componentClb();
      })
      .catch((error: Error) => {
        dispatch(myErrorAction());
      });
  };
}


Aucun commentaire:

Enregistrer un commentaire