-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwithApollo.js
36 lines (31 loc) · 924 Bytes
/
withApollo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from "react";
import T from "prop-types";
import { ApolloProvider } from "react-apollo";
import createApolloClient from "../createApolloClient";
// Gets the display name of a JSX component for dev tools
function getComponentDisplayName(Component) {
return Component.displayName || Component.name || "Unknown";
}
export default ComposedComponent => {
return class WithApollo extends React.Component {
static displayName = `WithData(${getComponentDisplayName(
ComposedComponent
)})`;
static propTypes = {
apolloClient: T.object
};
constructor(props) {
super(props);
this.apollo =
props.apolloClient ||
createApolloClient((window && window.__APOLLO_STATE__) || {});
}
render() {
return (
<ApolloProvider client={this.apollo}>
<ComposedComponent {...this.props} />
</ApolloProvider>
);
}
};
};