Created
July 10, 2019 09:13
-
-
Save radzserg/e3e39108f3f94bbda296a5e53fb01035 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| export default function withLogger<T>( | |
| WrappedComponent: React.ComponentType<T> | |
| ): React.ComponentType<T> { | |
| const name = WrappedComponent.displayName || WrappedComponent.name; | |
| class InjectionWrapper extends React.Component<any, any> { | |
| static contextType = LoggerContext; | |
| static displayName = `withLogger(${name})`; | |
| static WrappedComponent = WrappedComponent; | |
| render() { | |
| const logger = this.context as ILogger; | |
| const { ...restProps } = this.props; | |
| return <WrappedComponent logger={logger} {...(restProps as T)} />; | |
| } | |
| } | |
| return InjectionWrapper; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment