How to use the react.cloneElement function in react

To help you get started, weโ€™ve selected a few react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github salt-ui / saltui / src / ScrollList / ScrollList.jsx View on Github external
      return data.map((item, i) => React.cloneElement(lastChild, {
        /* eslint-disable react/no-array-index-key */
        key: `child-${i}`,
        /* selint-enable react/no-array-index-key */
        index: i,
        first: i === 0,
        last: i === len,
        odd: odd(i),
        data: item,
        ...item,
      }));
    }
github claus / react-dat-gui / src / components / DatFolder.js View on Github external
return React.Children.map(children, child =>
      cloneElement(child, { ...rest })
    );
github eggheadio-projects / start-learning-react / lessons / 19-react-use-react-cloneelement-to-extend-functionality-of-children-components / App.js View on Github external
let fn = child =>
        React.cloneElement(child, {
          onClick:this.selectItem.bind(this, child.props.value)
        })
      let items = React.Children.map(this.props.children, fn);
github trendmicro-frontend / react-dropdown / src / Dropdown.jsx View on Github external
let ref = c => {
            this.menu = c;
        };

        if (typeof child.ref === 'string') {
            warning(
                false,
                'String refs are not supported on `` components. ' +
                'To apply a ref to the component use the callback signature:\n\n ' +
                'https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute'
            );
        } else {
            ref = chainedFunction(child.ref, ref);
        }

        return cloneElement(child, {
            ...props,
            ref,
            onClose: chainedFunction(
                child.props.onClose,
                onClose,
                this.closeDropdown
            ),
            onSelect: chainedFunction(
                child.props.onSelect,
                onSelect,
                this.closeDropdown
            ),
            rootCloseEvent
        });
    }
github gregchamberlain / react-chips / src / Chips.js View on Github external
return this.props.value.map((chip, idx) => {
      return (
        React.cloneElement(this.props.renderChip(chip, this.props.chipTheme), {
          selected: this.state.chipSelected && idx === this.props.value.length - 1,
          onRemove: this.removeChip(idx),
          index: idx,
          key: `chip${idx}`,
        })
      );
    });
  }
github FormidableLabs / victory / packages / victory-candlestick / src / candle.js View on Github external
lineComponent,
    role,
    shapeRendering,
    className,
    wickStrokeWidth,
    transform,
    style
  } = props;
  const wickStyle = defaults({ strokeWidth: wickStrokeWidth }, style);
  const sharedProps = { role, shapeRendering, className, transform, clipPath, ...events };
  const candleProps = assign(getCandleProps(props, style), sharedProps);
  const highWickProps = assign(getHighWickProps(props, wickStyle), sharedProps);
  const lowWickProps = assign(getLowWickProps(props, wickStyle), sharedProps);

  return React.cloneElement(groupComponent, {}, [
    React.cloneElement(rectComponent, candleProps),
    React.cloneElement(lineComponent, highWickProps),
    React.cloneElement(lineComponent, lowWickProps)
  ]);
};
github salt-ui / saltui / lib / InfiniteScroll / InfiniteScroll.jsx View on Github external
render() {
    const element = React.Children.only(this.props.children);
    const elementChildren = React.Children.only(element.props.children);

    return React.cloneElement(element, {
      ...element.props,
      ref: (node) => {
        this.$scroller = node;
        this.props.getRef(node);
      },
      onScroll: this.onScroll,
      children: React.cloneElement(elementChildren, {
        children: [
          ...React.Children.toArray(elementChildren.props.children),
          this.scrollArea(),
        ],
      }),
    });
  }
}
github marmelab / react-admin / src / mui / list / List.js View on Github external
<div>
                            {children &amp;&amp;
                                React.cloneElement(children, {
                                    resource,
                                    ids,
                                    data,
                                    currentSort: {
                                        field: query.sort,
                                        order: query.order,
                                    },
                                    basePath,
                                    isLoading,
                                    setSort: this.setSort,
                                })}
                            {pagination &amp;&amp;
                                React.cloneElement(pagination, {
                                    total,
                                    page: parseInt(query.page, 10),
                                    perPage: parseInt(query.perPage, 10),
                                    setPage: this.setPage,
                                })}
                        </div>
                    ) : (
                        
                            {translate('aor.navigation.no_results')}
                        
                    )}
                
            
        );
    }
}
github bokuweb / re-bulma / src / elements / group.js View on Github external
cloneWithProps() {
    if (React.Children.count(this.props.children) &lt; 2) {
      return (
        <p>
          {this.props.children &amp;&amp; React.cloneElement(this.props.children, {
            hasAddons: true,
          })}
        </p>
      );
    }
    return this.props.children.map((child, i) =&gt; (
      <p>
        {React.cloneElement(child, { hasAddons: true })}
      </p>
    ));
  }