Skip to content

Instantly share code, notes, and snippets.

@jrwebdev
Last active April 1, 2019 13:28
Show Gist options
  • Select an option

  • Save jrwebdev/bed055c2e024045cc6fe93ac27e2c4f5 to your computer and use it in GitHub Desktop.

Select an option

Save jrwebdev/bed055c2e024045cc6fe93ac27e2c4f5 to your computer and use it in GitHub Desktop.
import { Subtract, Omit } from 'utility-types';
import MakeCounter, { MakeCounterProps, InjectedCounterProps } from './MakeCounter';
type MakeCounterHocProps = Omit<MakeCounterProps, 'children'>;
const makeCounter = <P extends InjectedCounterProps>(
Component: React.ComponentType<P>
): React.SFC<Subtract<P, InjectedCounterProps> & MakeCounterHocProps> => ({
minValue,
maxValue,
...props
}: MakeCounterHocProps) => (
<MakeCounter minValue={minValue} maxValue={maxValue}>
{injectedProps => <Component {...props as P} {...injectedProps} />}
</MakeCounter>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment