File tree Expand file tree Collapse file tree 1 file changed +21
-25
lines changed Expand file tree Collapse file tree 1 file changed +21
-25
lines changed Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react'
2
2
import Link from './Link'
3
- import { graphql } from 'react-apollo'
3
+ import { Query } from 'react-apollo'
4
4
import gql from 'graphql-tag'
5
5
6
- class LinkList extends Component {
7
- render ( ) {
8
- // 1
9
- if ( this . props . feedQuery && this . props . feedQuery . loading ) {
10
- return < div > Loading</ div >
11
- }
12
-
13
- // 2
14
- if ( this . props . feedQuery && this . props . feedQuery . error ) {
15
- return < div > Error</ div >
16
- }
17
-
18
- // 3
19
- const linksToRender = this . props . feedQuery . feed . links
20
-
21
- return (
22
- < div > { linksToRender . map ( link => < Link key = { link . id } link = { link } /> ) } </ div >
23
- )
24
- }
25
- }
26
-
27
6
// 1
28
7
const FEED_QUERY = gql `
29
8
# 2
@@ -37,7 +16,24 @@ const FEED_QUERY = gql`
37
16
}
38
17
}
39
18
}
40
- `
19
+ ` ;
20
+
21
+ class LinkList extends Component {
22
+ render ( ) {
23
+ return (
24
+ < Query query = { FEED_QUERY } >
25
+ { ( result ) => {
26
+ if ( result . loading ) return < div > Loading</ div > ;
27
+ if ( result . error ) return < div > Error</ div > ;
28
+
29
+ const { data } = result ;
30
+ const linksToRender = data . feed . links ;
31
+
32
+ return < div > { linksToRender . map ( link => < Link key = { link . id } link = { link } /> ) } </ div > ;
33
+ } }
34
+ </ Query >
35
+ )
36
+ }
37
+ }
41
38
42
- // 3
43
- export default graphql ( FEED_QUERY , { name : 'feedQuery' } ) ( LinkList )
39
+ export default LinkList ;
You can’t perform that action at this time.
0 commit comments