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

attach displayName to forwardRef function as described in React docs #2508

Merged
merged 2 commits into from May 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/styled-components/src/models/StyledComponent.js
Expand Up @@ -277,15 +277,18 @@ export default function createStyledComponent(target: Target, options: Object, r
* forwardRef creates a new interim component, which we'll take advantage of
* instead of extending ParentComponent to create _another_ interim class
*/
const WrappedStyledComponent = React.forwardRef((props, ref) => (
let WrappedStyledComponent;
const forwardRef = (props, ref) => (
<ParentComponent {...props} forwardedComponent={WrappedStyledComponent} forwardedRef={ref} />
));
);
forwardRef.displayName = displayName;
WrappedStyledComponent = React.forwardRef(forwardRef);
WrappedStyledComponent.displayName = displayName;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this one isn't needed if you put it on the underlying one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah but all tests fail otherwise, will need to understand how the tests check this


// $FlowFixMe
WrappedStyledComponent.attrs = finalAttrs;
// $FlowFixMe
WrappedStyledComponent.componentStyle = componentStyle;
WrappedStyledComponent.displayName = displayName;

// $FlowFixMe
WrappedStyledComponent.foldedComponentIds = isTargetStyledComp
Expand Down