samedi 8 juin 2019

How to pass large number of props to a react component to react render method

i have a redux container called (lets say) Parent which uses a Component in its render method called ButtonGroup which has a lot of props. Now a lot of these props take callback references, which are essentially redux container class methods, which refer to props from mapStateToProps & mapDispatchToProps and lot of container state.

My problem is - i do not want to write the component markup like

callBack() {}
callBack2() {}
render() { 
  return <ButtonGroup prop1={this.state.x} prop2={this.callBack} prop3={this.callback2}
}

so i refactored to below -

 getProps() {}
.
.
.
.
.
render() {
  return <ButtonGroup {...this.getProps()} />
}

My question is - is this way a performant one? or is there any more better performant way to do it??

Aucun commentaire:

Enregistrer un commentaire