Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Hoisted type
  • Loading branch information
Brian Vaughn committed May 29, 2018
commit dfa3dc628d34734979d640530a7242b1210e23fc
16 changes: 9 additions & 7 deletions packages/react/src/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ if (__DEV__) {
return '#text';
} else if (typeof element.type === 'string') {
return element.type;
} else if (element.type === REACT_FRAGMENT_TYPE) {
}

const type = element.type;
if (type === REACT_FRAGMENT_TYPE) {
return 'React.Fragment';
} else if (
typeof element.type === 'object' &&
element.type !== null &&
element.type.$$typeof === REACT_FORWARD_REF_TYPE
typeof type === 'object' &&
type !== null &&
type.$$typeof === REACT_FORWARD_REF_TYPE
) {
const functionName =
element.type.render.displayName || element.type.render.name || '';
const functionName = type.render.displayName || type.render.name || '';
return functionName !== '' ? `ForwardRef(${functionName})` : 'ForwardRef';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this look like getComponentName duplication here? Can we unify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's similar. But getComponentName accepts a Fiber and this is a ReactElement.

We could refactor both to use a shared helper, but it didn't seem like the obvious correct thing to do in this case.

} else {
return element.type.displayName || element.type.name || 'Unknown';
return type.displayName || type.name || 'Unknown';
}
};

Expand Down