Created
May 29, 2018 09:59
-
-
Save stephenwil/f7af01bda7d363d004729ec9125d85a7 to your computer and use it in GitHub Desktop.
Typescript HOC Context
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 const withContext = <P extends {}>(Component: React.ComponentType<P>) => | |
class WithContext extends React.PureComponent<P & IAppContext> { | |
render() { | |
return ( | |
<AppContext.Consumer> | |
{(context: any) => <Component {...this.props} {...context} />} | |
</AppContext.Consumer> | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why
(context: any)
? It should be(context: IAppContext)
, I guess