mercredi 5 décembre 2018

Create an objcet and spreading it as props of a React Element it's a good or bad pattern?

It's a good or bad pattern spread an object as props like this and why ? and in case it's a bad patter what's the best choice in this case ?

Thanks :D

render() {

    let theProps = {
      wrapper: {
        image: this.props.image,
        pattern: pattern,
        open: this.state.open
      },
      ctaButton: {
        showCondition: (typeof this.props.ctaText === "string") && (this.props.ctaText.length > 0),
        className: "bz-big bz-white bz-z-element",
        children: <FormattedMessage id={this.props.ctaText} />,
        action: this.props.ctaAction
      }
    };

    return (
      <Wrap {...theProps.wrapper}>
        <ActionButton {...theProps.ctaButton} />
      </Wrap>
    );
  }

Aucun commentaire:

Enregistrer un commentaire