withInjected -> PureComponent (fix new refs) (#1195)

* withInjected -> PureComponent (fix new refs)

* Consume data from context

* Expand injected
This commit is contained in:
Jaco Greeff 2019-05-23 14:16:04 +02:00 committed by GitHub
parent fb8b2bf20c
commit cb522a4263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,18 +27,19 @@ export {
};
export function withInjected<P extends ApiInjectedProps> (Component: React.ComponentType<P>): React.ComponentType<Subtract<P, ApiInjectedProps>> {
return (props: Subtract<P, ApiInjectedProps>) => {
return (
<InjectedContext.Consumer>
{(injected) => (
// @ts-ignore Something here with the props are going wonky
<Component
{...props}
injectedAvailable={injectedAvailable}
injectedPromise={injectedPromise}
/>
)}
</InjectedContext.Consumer>
);
return class extends React.PureComponent<Subtract<P, ApiInjectedProps>> {
render () {
return (
<InjectedContext.Consumer>
{(injected) => (
// @ts-ignore Something here with the props are going wonky
<Component
{...this.props}
{...injected}
/>
)}
</InjectedContext.Consumer>
);
}
};
}