Skip to content

Instantly share code, notes, and snippets.

@yaralahruthik
Created December 7, 2021 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaralahruthik/27f2bf8afebd8a06bac87c17a2b07822 to your computer and use it in GitHub Desktop.
Save yaralahruthik/27f2bf8afebd8a06bac87c17a2b07822 to your computer and use it in GitHub Desktop.
import { useQuery } from 'react-query';
import { getTodos } from '../services/todoReactQuery';
const ReactQueryWay = () => {
const { isLoading, error, data } = useQuery('todos', getTodos);
if (isLoading) return 'Loading...';
if (error) return 'An error has occurred: ' + error.message;
return (
<div>
<h1>React Query Way</h1>
{error ? (
<>Oh no, there was an error</>
) : isLoading ? (
<>Loading...</>
) : data ? (
<>
<ul>
{data.map((item) => (
<li key={item.id}>{item.title}</li>
))}
</ul>
</>
) : null}
</div>
);
};
export default ReactQueryWay;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment