Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce forward references in pretty printer #6069

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Changes from all 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
9 changes: 9 additions & 0 deletions packages/pretty-format/src/plugins/react_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {

const elementSymbol = Symbol.for('react.element');
const fragmentSymbol = Symbol.for('react.fragment');
const forwardRefSymbol = Symbol.for('react.forward_ref');

// Given element.props.children, or subtree during recursive traversal,
// return flattened array of children.
Expand All @@ -42,6 +43,14 @@ const getType = element => {
if (element.type === fragmentSymbol) {
return 'React.Fragment';
}
if (element.type === forwardRefSymbol) {
const functionName =
element.type.render.displayName || element.type.render.name || '';

return functionName !== ''
? 'ForwardRef(' + functionName + ')'
: 'ForwardRef';
}
return 'UNDEFINED';
};

Expand Down