MCPcopy Index your code
hub / github.com/microsoft/SandDance / cloneElement

Function cloneElement

docs/external/js/react.development.js:903–973  ·  view source on GitHub ↗

* Clone and return a new ReactElement using element as the starting point. * See https://reactjs.org/docs/react-api.html#cloneelement

(element, config, children)

Source from the content-addressed store, hash-verified

901 */
902
903 function cloneElement(element, config, children) {
904 if (!!(element === null || element === undefined)) {
905 {
906 throw Error( "React.cloneElement(...): The argument must be a React element, but you passed " + element + "." );
907 }
908 }
909
910 var propName; // Original props are copied
911
912 var props = objectAssign({}, element.props); // Reserved names are extracted
913
914
915 var key = element.key;
916 var ref = element.ref; // Self is preserved since the owner is preserved.
917
918 var self = element._self; // Source is preserved since cloneElement is unlikely to be targeted by a
919 // transpiler, and the original source is probably a better indicator of the
920 // true owner.
921
922 var source = element._source; // Owner will be preserved, unless ref is overridden
923
924 var owner = element._owner;
925
926 if (config != null) {
927 if (hasValidRef(config)) {
928 // Silently steal the ref from the parent.
929 ref = config.ref;
930 owner = ReactCurrentOwner.current;
931 }
932
933 if (hasValidKey(config)) {
934 key = '' + config.key;
935 } // Remaining properties override existing props
936
937
938 var defaultProps;
939
940 if (element.type && element.type.defaultProps) {
941 defaultProps = element.type.defaultProps;
942 }
943
944 for (propName in config) {
945 if (hasOwnProperty$1.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
946 if (config[propName] === undefined && defaultProps !== undefined) {
947 // Resolve default props
948 props[propName] = defaultProps[propName];
949 } else {
950 props[propName] = config[propName];
951 }
952 }
953 }
954 } // Children can be more than one argument, and those are transferred onto
955 // the newly allocated props object.
956
957
958 var childrenLength = arguments.length - 2;
959
960 if (childrenLength === 1) {

Callers

nothing calls this directly

Calls 3

hasValidRefFunction · 0.85
hasValidKeyFunction · 0.85
ReactElementFunction · 0.85

Tested by

no test coverage detected