Last active
February 8, 2022 01:02
-
-
Save ilxanlar/a413fcf3b33a30e7b19832e329d23a16 to your computer and use it in GitHub Desktop.
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 { 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