bora89
3/22/2017 - 12:41 PM

react pass props to this.props.children

react pass props to this.props.children

/**
     * pass props to this.props.children
     * see http://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-props-children
     */
    const childrenWithProps = React.Children.map(this.props.children,
      (child) => React.cloneElement(child, {
        onGo: (value) => {
          // invoke child onGo event (if any)
          if (child.props.onGo) {
            child.props.onGo(value);
          }
          // do our own logic
          this.enterResultMode();
        }
      })
    );