How to use the cloneElement function from react

Find comprehensive JavaScript react.cloneElement code examples handpicked from public code repositorys.

120
121
122
123
124
125
126
127
128
129
  function() {
    _this.setDropdown(false);
  }
) : onClick;

return React.cloneElement(
  child,
  assign({}, child.props, {
    key: `dropdownItem-${index}`,
    onClick: handleClick
fork icon235
star icon0
watch icon2

22
23
24
25
26
27
28
29
30
      }
      return child;
    });
  }
  if(children.type === ParallaxImage) {
    return React.cloneElement(children, props);
  }
  return children;
};
fork icon82
star icon578
watch icon15

+ 3 other calls in file

16
17
18
19
20
21
22
23
24
var separatorIsElement = React.isValidElement(separator);
var items = [children.shift()];
children.forEach(function(item, index) {
        if (separatorIsElement) {
                var key = 'separator-' + (item.key || index);
                separator = React.cloneElement(separator, { key: key });
        }
        items.push(separator, item);
});
fork icon3
star icon48
watch icon3

4
5
6
7
8
9
10
11
12
13
return {
  converters: [
    [
      function (node) { return typeof node === 'function'; },
      function (node, index) {
        return React.cloneElement(node(), { key: index });
      },
    ],
  ],
};
fork icon430
star icon0
watch icon64

48
49
50
51
52
53
54
55
56
57
    </div>
  );
},

renderChildBar: function(child, index) {
  return React.cloneElement(child, {
    isChild: true,
    key: child.key ? child.key : index
  });
},
fork icon235
star icon0
watch icon92

127
128
129
130
131
132
133
134
135
136
  { this.render_nav_menu() }
</Drawer>

<div id="container" className="container">
  <div className="app-content">
    { React.cloneElement(this.props.children, { user: user, signing_in: this.state.signing_in }) }
  </div>
</div>

<ReactTooltip place="top" effect="solid" />
fork icon190
star icon0
watch icon50

158
159
160
161
162
163
164
165
166
167

renderTabBar(props) {
  if (this.props.renderTabBar === false) {
    return null;
  } else if (this.props.renderTabBar) {
    return React.cloneElement(this.props.renderTabBar(props), props);
  } else {
    return <DefaultTabBar {...props} />;
  }
},
fork icon0
star icon0
watch icon0

111
112
113
114
115
116
117
118
119
      let children = [checkboxColumn];
      React.Children.forEach(child.props.children, (child) => {
        children.push(child);
      });

      return React.cloneElement(child, {...props, ...handlers}, children);
    }
  });
},
fork icon0
star icon0
watch icon17