Skip to content

Commit ad11efa

Browse files
author
Daniel Schmidt
committed
docs: add usage example
1 parent 5804151 commit ad11efa

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Reactive GraphQL React
2+
3+
React Hook bindings for [reactive-graphql](https://github.com/mesosphere/reactive-graphql).
4+
5+
## Usage
6+
7+
```ts
8+
import getReactiveGraphqlReact from "reactive-graphql-react";
9+
10+
const schema = getSchema(); // get a GraphQL schema
11+
const queryGraphql = getReactiveGraphqlReact(schema); // get the hook
12+
13+
export default function MyComponent() {
14+
// Always up-to-date data
15+
const [result, error] = queryGraphql(`
16+
query {
17+
posts {
18+
title
19+
author {
20+
name
21+
}
22+
}
23+
}
24+
`);
25+
if (error) {
26+
return <h3>There has been an error fetching the data</h3>;
27+
}
28+
29+
if (!result) {
30+
return <h3>Loading, please wait</h3>;
31+
}
32+
33+
const {
34+
data: { posts }
35+
} = result;
36+
37+
return <PostList items={posts} />;
38+
}
39+
```
40+
41+
## License
42+
43+
MIT

0 commit comments

Comments
 (0)