Skip to content

Instantly share code, notes, and snippets.

@mbohgard
Created January 30, 2019 12:35
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 mbohgard/812899bba33e11f2b94dfc976f3970dd to your computer and use it in GitHub Desktop.
Save mbohgard/812899bba33e11f2b94dfc976f3970dd to your computer and use it in GitHub Desktop.
TypeScript HOC
export type WithProps = {
prop: SomeType;
};
const value: SomeType = true;
export const withProp = <P extends WithProps>(
Component: React.ComponentType<P>
): React.SFC<Subtract<P, WithProps>> => props => (
return value ? (
<Component {...props as any} prop={value} />
) : (
<noscript />
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment