Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react/src/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ export function createElementWithValidation(type, props, children) {
typeString = 'array';
} else {
typeString = typeof type;
if (type && type.hasOwnProperty('$$typeof')) {
typeString = 'element';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"React element" would be better here.

Also now that I think of it let's compare type.$$typeof === REACT_ELEMENT_TYPE explicitly. We don't actually "own" this convention. You can get REACT_ELEMENT_TYPE from existing ReactSymbols import in this file.

info = ' Did you accidentally export JSX instead of a component?';
}
}

warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ describe('ReactElementValidator', () => {
React.createElement(true);
React.createElement({x: 17});
React.createElement({});
React.createElement(React.createElement('div'));
}).toWarnDev([
'Warning: React.createElement: type is invalid -- expected a string ' +
'(for built-in components) or a class/function (for composite ' +
Expand All @@ -255,6 +256,10 @@ describe('ReactElementValidator', () => {
'components) but got: object. You likely forgot to export your ' +
"component from the file it's defined in, or you might have mixed up " +
'default and named imports.',
'Warning: React.createElement: type is invalid -- expected a string ' +
'(for built-in components) or a class/function (for composite ' +
'components) but got: element. Did you accidentally export JSX ' +
'instead of a component?',
]);

// Should not log any additional warnings
Expand Down