Skip to content

Instantly share code, notes, and snippets.

@stephenwil
Created May 29, 2018 09:59
Show Gist options
  • Save stephenwil/f7af01bda7d363d004729ec9125d85a7 to your computer and use it in GitHub Desktop.
Save stephenwil/f7af01bda7d363d004729ec9125d85a7 to your computer and use it in GitHub Desktop.
Typescript HOC Context
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>
);
}
};
@serhiiminin
Copy link

Why (context: any) ? It should be (context: IAppContext), I guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment