Skip to content

Instantly share code, notes, and snippets.

@thomasboyt
Created January 7, 2017 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasboyt/b9fb54f9a0309ca8027bb7da481a10e7 to your computer and use it in GitHub Desktop.
Save thomasboyt/b9fb54f9a0309ca8027bb7da481a10e7 to your computer and use it in GitHub Desktop.
import * as React from 'react';
import {ColorScheme} from '../../universal/resources';
interface Context {
colorScheme: ColorScheme;
}
/**
* Injects this.context.colorScheme as a prop
*/
export default function withColorScheme<C extends React.ComponentClass<any>>(Component: C): C {
return class ColorSchemeWrapper extends React.Component<any, {}> {
context: Context;
static contextTypes = {
colorScheme: React.PropTypes.object.isRequired,
};
render() {
const {colorScheme} = this.context;
return <Component {...this.props} colorScheme={colorScheme} />;
}
}
}
// line 13: [ts] Type 'typeof ColorSchemeWrapper' is not assignable to type 'C'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment