0

Let's say I have this action from the redux store:

const mapDispatchToProps = dispatch => {
    return {
        someaction: bindActionCreators(someaction, dispatch)
    };
};

When I need to use it inside my component do I..

1 - Use the action directly as props:

<SomeInnerComponent onClick={this.props.someaction} />

OR:

2 - Create a method in the component which calls the action. Then call that method in my render():

someAction() {
  this.props.someaction();
}
render() {
  <SomeInnerComponent onClick={this.someAction} />
}

What is the best practice?

Joshua
  • 3,055
  • 3
  • 22
  • 37
catandmouse
  • 11,309
  • 23
  • 92
  • 150
  • Just use the action directly. There's no point to a component method that just calls an action and nothing else. Just adding an unnecessary method call in between. – Jayce444 Sep 07 '18 at 07:34
  • @BhojendraRauniyar Think my question is quite different. – catandmouse Sep 07 '18 at 07:35
  • @catandmouse that should help you deciding in this scenario as well, I think. – Bhojendra Rauniyar Sep 07 '18 at 07:36
  • Why create another method if his purpose is just to call the action while you can just call this action?! Just call it. You can cal another method if you have to achieve others stuffs. – mcssym Sep 07 '18 at 07:55

0 Answers0