Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function createElement(type, config, ...children) {
- var propName;
- // Reserved names are extracted
- var props = {};
- var key = null;
- var ref = null;
- var self = null;
- var source = null;
- if (config != null) {
- if (hasValidRef(config)) {
- ref = config.ref;
- }
- if (hasValidKey(config)) {
- key = '' + config.key;
- }
- self = config.__self === undefined ? null : config.__self;
- source = config.__source === undefined ? null : config.__source;
- // Remaining properties are added to a new props object
- for (propName in config) {
- if (
- hasOwnProperty.call(config, propName) &&
- !RESERVED_PROPS.hasOwnProperty(propName)
- ) {
- props[propName] = config[propName];
- }
- }
- }
- // Children can be more than one argument, and those are transferred onto
- // the newly allocated props object.
- var childrenLength = children.length;
- if (childrenLength === 1) {
- props.children = children[0];
- } else if (childrenLength > 1) {
- props.children = children;
- }
- // Resolve default props
- if (type && type.defaultProps) {
- var defaultProps = type.defaultProps;
- for (propName in defaultProps) {
- if (props[propName] === undefined) {
- props[propName] = defaultProps[propName];
- }
- }
- }
- if (__DEV__) {
- if (key || ref) {
- if (
- typeof props.$$typeof === 'undefined' ||
- props.$$typeof !== REACT_ELEMENT_TYPE
- ) {
- var displayName =
- typeof type === 'function'
- ? type.displayName || type.name || 'Unknown'
- : type;
- if (key) {
- defineKeyPropWarningGetter(props, displayName);
- }
- if (ref) {
- defineRefPropWarningGetter(props, displayName);
- }
- }
- }
- }
- return ReactElement(
- type,
- key,
- ref,
- self,
- source,
- ReactCurrentOwner.current,
- props,
- );
- }
Add Comment
Please, Sign In to add comment