The code you provided seems to have some syntax errors and incorrect imports. Here's a corrected version of the code using react-query version 4:
import { useQuery } from 'react-query';
export default function Reddit() {
const { data: posts, isLoading, isError, error, isSuccess } = useQuery('posts', fetchPosts);
function fetchPosts() {
return fetch('https://www.reddit.com/r/aww.json').then(response => response.json());
}
return (
<div>
<h1>Reddit API</h1>
{isLoading && <p>Loading...</p>}
{isSuccess && (
<ul>
{posts.data.children.map(post => (
<li key={post.data.id}>
<a href={`https://reddit.com${post.data.permalink}`} target="_blank" rel="noreferrer noopener nofollow">
{post.data.title}
</a>
</li>
))}
</ul>
)}
{isError && <div>{error.message}</div>}
</div>
);
}
Make sure you have installed the correct version of react-query (npm install react-query@4) and imported it correctly (import { useQuery } from 'react-query').