// Children can be more than one argument, and those are transferred onto // the newly allocated props object. const childrenLength = arguments.length - 2; if (childrenLength === 1) { props.children = children; } elseif (childrenLength > 1) { const childArray = Array(childrenLength); for (let i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 2]; } if (__DEV__) { if (Object.freeze) { Object.freeze(childArray); } } props.children = childArray; }
// 挂载defaultProps if (type && type.defaultProps) { const defaultProps = type.defaultProps; for (propName in defaultProps) { if (props[propName] === undefined) { props[propName] = defaultProps[propName]; } } } returnReactElement( type, key, ref, self, source, ReactCurrentOwner.current, // 应该是有fiber中注入的 暂时不用理 props, ); }
ReactElement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
constReactElement = function(type, key, ref, self, source, owner, props) { const element = { // This tag allows us to uniquely identify this as a React Element // 用来判断是否为React Element $$typeof: REACT_ELEMENT_TYPE,
// Built-in properties that belong on the element type: type, key: key, ref: ref, props: props,
// Record the component responsible for creating this element. _owner: owner, };