Skip to content

Instantly share code, notes, and snippets.

@ilxanlar
Last active February 8, 2022 01:02
Show Gist options
  • Save ilxanlar/a413fcf3b33a30e7b19832e329d23a16 to your computer and use it in GitHub Desktop.
Save ilxanlar/a413fcf3b33a30e7b19832e329d23a16 to your computer and use it in GitHub Desktop.
import React from 'react'
import { useQuery } from 'react-query'
import LikeTweet from './LikeTweet'
const fetchTweets = async () => {
// Fetch tweets from the API
}
function Tweets() {
const { data, isError, isLoading } = useQuery('tweets', fetchTweets);
if (isError) {
return <p>Failed to load tweets.</p>
}
if (isLoading) {
return <p>Loading tweets...</p>
}
return (
<ul>
{data.map(tweet => (
<li key={tweet.id}>
<small>{tweet.username}</small>
<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