Skip to content

Instantly share code, notes, and snippets.

@ilxanlar
Last active April 12, 2021 13:20
Show Gist options
  • Save ilxanlar/d8b015a46fed0ee30bc6d7b6b26681cc to your computer and use it in GitHub Desktop.
Save ilxanlar/d8b015a46fed0ee30bc6d7b6b26681cc to your computer and use it in GitHub Desktop.
import React from 'react'
import { gql, useQuery } from '@apollo/client'
const GET_TWEETS = gql`
query {
tweets {
id
text
is_liked
}
}
`
function Tweets() {
const { data, loading } = useQuery(GET_TWEETS)
if (loading) {
return (
<p>Loading tweets...</p>
)
}
const tweets = data?.tweets || []
return (
<ul className="tweets">
{tweets.map(tweet => (
<li key={tweet.id}>
<p>{tweet.text}</p>
<footer>
...
<LikeTweet tweetId={tweet.id} isLiked={tweet.is_liked} />
...
</footer>
</li>
))}
</ul>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment