Created
December 7, 2021 16:28
-
-
Save yaralahruthik/27f2bf8afebd8a06bac87c17a2b07822 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 { 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