Created
November 25, 2019 21:39
-
-
Save wendelnascimento/ee78a87ae05cff7b3cf284b1c69e3a20 to your computer and use it in GitHub Desktop.
Post List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Flex, Box } from '@primer/components'; | |
import { useQuery } from '@apollo/react-hooks'; | |
import gql from 'graphql-tag'; | |
import PostItem from '../PostItem/PostItem'; | |
const GET_POSTS_QUERY = gql` | |
query posts { | |
posts { | |
id | |
picture | |
description | |
claps | |
} | |
} | |
`; | |
const PostList = (props) => { | |
const { loading, data } = useQuery(GET_POSTS_QUERY); | |
if (loading) { | |
return null; | |
} | |
return ( | |
<Flex p={5} width="100%" minHeight="100vh" justifyContent="center" alignItems="flex-start"> | |
<Flex flexDirection="column"> | |
{ | |
data.posts.map(post => ( | |
<Box p={3} key={post.id}> | |
<PostItem post={post} /> | |
</Box> | |
)) | |
} | |
</Flex> | |
</Flex> | |
); | |
}; | |
export default PostList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment