MCPcopy Create free account
hub / github.com/plotly/dash / cloneElement

Function cloneElement

dash/deps/react@18.2.0.js:867–938  ·  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

865 */
866
867 function cloneElement(element, config, children) {
868 if (element === null || element === undefined) {
869 throw new Error("React.cloneElement(...): The argument must be a React element, but you passed " + element + ".");
870 }
871
872 var propName; // Original props are copied
873
874 var props = assign({}, element.props); // Reserved names are extracted
875
876 var key = element.key;
877 var ref = element.ref; // Self is preserved since the owner is preserved.
878
879 var self = element._self; // Source is preserved since cloneElement is unlikely to be targeted by a
880 // transpiler, and the original source is probably a better indicator of the
881 // true owner.
882
883 var source = element._source; // Owner will be preserved, unless ref is overridden
884
885 var owner = element._owner;
886
887 if (config != null) {
888 if (hasValidRef(config)) {
889 // Silently steal the ref from the parent.
890 ref = config.ref;
891 owner = ReactCurrentOwner.current;
892 }
893
894 if (hasValidKey(config)) {
895 {
896 checkKeyStringCoercion(config.key);
897 }
898
899 key = '' + config.key;
900 } // Remaining properties override existing props
901
902
903 var defaultProps;
904
905 if (element.type && element.type.defaultProps) {
906 defaultProps = element.type.defaultProps;
907 }
908
909 for (propName in config) {
910 if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
911 if (config[propName] === undefined && defaultProps !== undefined) {
912 // Resolve default props
913 props[propName] = defaultProps[propName];
914 } else {
915 props[propName] = config[propName];
916 }
917 }
918 }
919 } // Children can be more than one argument, and those are transferred onto
920 // the newly allocated props object.
921
922
923 var childrenLength = arguments.length - 2;
924

Callers

nothing calls this directly

Calls 4

hasValidRefFunction · 0.70
hasValidKeyFunction · 0.70
checkKeyStringCoercionFunction · 0.70
ReactElementFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…