Skip to content

Commit 25aed60

Browse files
author
Carlos Rufo Jimenez
committed
2-end-queries
1 parent bb4a82f commit 25aed60

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

src/components/LinkList.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
11
import React, { Component } from 'react'
22
import Link from './Link'
3-
import { graphql } from 'react-apollo'
3+
import { Query } from 'react-apollo'
44
import gql from 'graphql-tag'
55

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-
276
// 1
287
const FEED_QUERY = gql`
298
# 2
@@ -37,7 +16,24 @@ const FEED_QUERY = gql`
3716
}
3817
}
3918
}
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+
}
4138

42-
// 3
43-
export default graphql(FEED_QUERY, { name: 'feedQuery' }) (LinkList)
39+
export default LinkList;

0 commit comments

Comments
 (0)