Skip to content

Commit 41e586c

Browse files
committed
feat(withQueryComponent): query comp
1 parent dd489a2 commit 41e586c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,39 @@ withQueryData(
1515

1616
Same functionality as `react-apollo` `graphql` HOC, except the `data` prop or named data prop is flattened.
1717

18+
### `withQueryComponent()`
19+
20+
```js
21+
withQueryComponent(
22+
queryDocument: DocumentNode,
23+
optionsObject: { options: (props) => { variables } } | { options: Object }
24+
): Component
25+
```
26+
27+
Return a query component given a GraphQL document and options. What's returned is a Component
28+
with a render `child` that has the data object from `react-apollo`, see below.
29+
30+
Query Components outlined:
31+
https://dev-blog.apollodata.com/query-components-with-apollo-ec603188c157
32+
33+
```js
34+
const CitiesQuery = withQueryComponent(cityQuery);
35+
36+
function Sample() {
37+
return (
38+
<CitiesQuery>
39+
{
40+
(data) => {
41+
return (
42+
<p> I am loading? {data.loading ? 'Yes' : 'No'}
43+
);
44+
}
45+
}
46+
</CitiesQuery>
47+
);
48+
}
49+
```
50+
1851
### `withSubscribe()`
1952
2053
```js

withQueryComponent.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { graphql } from 'react-apollo';
2+
3+
function RenderChild({ data, children }) {
4+
return children(data);
5+
}
6+
7+
export default function withQueryComponent(queryDocument, optionsObject) {
8+
const queryData = graphql(queryDocument, optionsObject);
9+
return queryData(RenderChild);
10+
}

0 commit comments

Comments
 (0)