-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- This HOC allows styles to be injected without `ThemeProvider`
- Loading branch information
1 parent
c8550a7
commit bfb808e
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import hoistNonReactStatic from 'hoist-non-react-statics'; | ||
import * as React from 'react'; | ||
|
||
const withStyles = (styles: object) => (WrappedComponent: any): any => { | ||
const displayName = | ||
WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
|
||
class WithStyles extends React.Component { | ||
public render() { | ||
return <WrappedComponent {...this.props} wrappedStyles={styles} />; | ||
} | ||
} | ||
|
||
(WithStyles as any).displayName = `WithStyles(${displayName})`; | ||
hoistNonReactStatic(WithStyles, WrappedComponent); | ||
|
||
return WithStyles; | ||
}; | ||
|
||
export default withStyles; |