MCPcopy Index your code
hub / github.com/preactjs/preact / cloneElement

Function cloneElement

src/clone-element.js:14–48  ·  view source on GitHub ↗
(vnode, props, children)

Source from the content-addressed store, hash-verified

12 * @returns {import('./internal').VNode}
13 */
14export function cloneElement(vnode, props, children) {
15 let normalizedProps = assign({}, vnode.props),
16 key,
17 ref,
18 i;
19
20 let defaultProps;
21
22 if (vnode.type && vnode.type.defaultProps) {
23 defaultProps = vnode.type.defaultProps;
24 }
25
26 for (i in props) {
27 if (i == 'key') key = props[i];
28 else if (i == 'ref') ref = props[i];
29 else if (props[i] === UNDEFINED && defaultProps != UNDEFINED) {
30 normalizedProps[i] = defaultProps[i];
31 } else {
32 normalizedProps[i] = props[i];
33 }
34 }
35
36 if (arguments.length > 2) {
37 normalizedProps.children =
38 arguments.length > 3 ? slice.call(arguments, 2) : children;
39 }
40
41 return createVNode(
42 vnode.type,
43 normalizedProps,
44 key || vnode.key,
45 ref || vnode.ref,
46 NULL
47 );
48}

Callers

nothing calls this directly

Calls 2

assignFunction · 0.90
createVNodeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…