Skip to content

Instantly share code, notes, and snippets.

@thehappybug
Created June 15, 2018 19:05
Show Gist options
  • Select an option

  • Save thehappybug/88342c122cfb1df9f14c9a10fb4926e4 to your computer and use it in GitHub Desktop.

Select an option

Save thehappybug/88342c122cfb1df9f14c9a10fb4926e4 to your computer and use it in GitHub Desktop.

Revisions

  1. thehappybug created this gist Jun 15, 2018.
    16 changes: 16 additions & 0 deletions AppContext.tsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

    export function withAppContext<
    P extends { appContext?: AppContextInterface },
    R = Omit<P, 'appContext'>
    >(
    Component: React.ComponentClass<P> | React.StatelessComponent<P>
    ): React.SFC<R> {
    return function BoundComponent(props: R) {
    return (
    <AppContextConsumer>
    {value => <Component {...props} appContext={value} />}
    </AppContextConsumer>
    );
    };
    }