File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments