MCPcopy
hub / github.com/preactjs/preact / createElement

Function createElement

src/create-element.js:16–43  ·  view source on GitHub ↗
(type, props, children)

Source from the content-addressed store, hash-verified

14 * @returns {import('./internal').VNode}
15 */
16export function createElement(type, props, children) {
17 let normalizedProps = {},
18 key,
19 ref,
20 i;
21 for (i in props) {
22 if (i == 'key') key = props[i];
23 else if (i == 'ref') ref = props[i];
24 else normalizedProps[i] = props[i];
25 }
26
27 if (arguments.length > 2) {
28 normalizedProps.children =
29 arguments.length > 3 ? slice.call(arguments, 2) : children;
30 }
31
32 // If a Component VNode, check for and apply defaultProps
33 // Note: type may be undefined in development, must never error here.
34 if (typeof type == 'function' && type.defaultProps != NULL) {
35 for (i in type.defaultProps) {
36 if (normalizedProps[i] === UNDEFINED) {
37 normalizedProps[i] = type.defaultProps[i];
38 }
39 }
40 }
41
42 return createVNode(type, normalizedProps, key, ref, NULL);
43}
44
45/**
46 * Create a VNode (used internally by Preact)

Callers 14

renderFunction · 0.90
StaticContentFunction · 0.85
suspense.jsFile · 0.85
LazyFunction · 0.85
PortalFunction · 0.85
createPortalFunction · 0.85
MemoedFunction · 0.85
AppFunction · 0.85
svg.test.jsxFile · 0.85
ParentFunction · 0.85
preact.tsxFile · 0.85

Calls 1

createVNodeFunction · 0.70

Tested by 3

StaticContentFunction · 0.68
AppFunction · 0.68
ParentFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…