Skip to content

Commit

Permalink
Copy over all statics to avoid errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora Tarano committed Aug 23, 2019
1 parent 9b447c6 commit 713e189
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/withStylesWithHooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,22 @@ export function withStylesWithHooks(
WithStyles.defaultProps = { ...WrappedComponent.defaultProps };
}
WithStyles.contextTypes = contextTypes;
// Set statics on the component
WithStyles.WrappedComponent = WrappedComponent;
WithStyles.displayName = `withStyles(${wrappedComponentName})`;
WithStyles = hoistNonReactStatics(WithStyles, WrappedComponent);

// Make into a pure functional component if requested
if (pureComponent) {
WithStyles = React.memo(WithStyles);
let WithStylesMemo = React.memo(WithStyles);
// We set statics on the memoized component as well because the
// React.memo HOC doesn't copy them over
WithStyles.WrappedComponent = WrappedComponent;
WithStyles.displayName = `withStyles(${wrappedComponentName})`;
WithStyles = hoistNonReactStatics(WithStyles, WrappedComponent);
WithStylesMemo.propTypes = WithStyles.propTypes;
WithStylesMemo.defaultProps = WithStyles.defaultProps;
WithStylesMemo.contextTypes = WithStyles.contextTypes;
WithStylesMemo.WrappedComponent = WrappedComponent;
WithStylesMemo.displayName = `withStyles(${wrappedComponentName})`;
WithStylesMemo = hoistNonReactStatics(WithStylesMemo, WrappedComponent);
return WithStylesMemo;
}

return WithStyles;
Expand Down

0 comments on commit 713e189

Please sign in to comment.