@@ -5,3 +5,66 @@ url: https://github.com/nearform/graphql-hooks
5
5
github : nearform/graphql-hooks
6
6
npm : " graphql-hooks"
7
7
---
8
+
9
+ - 🥇 First-class hooks API
10
+ - ⚖️ _ Tiny_ bundle: only 7.6kB (2.8 gzipped)
11
+ - 📄 Full SSR support: see [ graphql-hooks-ssr] ( packages/graphql-hooks-ssr )
12
+ - 🔌 Plugin Caching: see [ graphql-hooks-memcache] ( packages/graphql-hooks-memcache )
13
+ - 🔥 No more render props hell
14
+ - ⏳ Handle loading and error states with ease
15
+
16
+ ### Quickstart
17
+
18
+ ``` bash
19
+ npm install graphql-hooks
20
+ ```
21
+
22
+ First you'll need to create a client and wrap your app with the provider:
23
+
24
+ ``` js
25
+ import { GraphQLClient , ClientContext } from ' graphql-hooks'
26
+
27
+ const client = new GraphQLClient ({
28
+ url: ' /graphql'
29
+ })
30
+
31
+ function App () {
32
+ return (
33
+ < ClientContext .Provider value= {client}>
34
+ {/* children */ }
35
+ < / ClientContext .Provider >
36
+ )
37
+ }
38
+ ```
39
+
40
+ Now in your child components you can make use of ` useQuery ` :
41
+
42
+ ``` js
43
+ import { useQuery } from ' graphql-hooks'
44
+
45
+ const HOMEPAGE_QUERY = ` query HomePage($limit: Int) {
46
+ users(limit: $limit) {
47
+ id
48
+ name
49
+ }
50
+ }`
51
+
52
+ function MyComponent () {
53
+ const { loading , error , data } = useQuery (HOMEPAGE_QUERY , {
54
+ variables: {
55
+ limit: 10
56
+ }
57
+ })
58
+
59
+ if (loading) return ' Loading...'
60
+ if (error) return ' Something Bad Happened'
61
+
62
+ return (
63
+ < ul>
64
+ {data .users .map (({ id, name }) => (
65
+ < li key= {id}> {name}< / li>
66
+ ))}
67
+ < / ul>
68
+ )
69
+ }
70
+ ```
0 commit comments