is it considered good practice to pass callBacks to redux async action?

后端 未结 3 1911
鱼传尺愫
鱼传尺愫 2020-12-04 15:47

I want to show different notification bars for success/error responses, I pass two callBacks to an redux async action in my react component like this:



        
3条回答
  •  半阙折子戏
    2020-12-04 16:08

    The pattern is fine per se. If this is a notification local to the component, feel free to avoid wiring it through Redux.

    That said callbacks are completely unnecessary because you are already returning the promise. Just wait for its completion.

    this.props.dispatch(asyncAction(item)).then(onSuccess, onFailure);
    

    However if you have many components with such notification bars, it's better to have a reducer keeping the current notification and reacting to actions.

提交回复
热议问题