Last active
October 21, 2021 15:26
-
-
Save VithuJey/d272e969a7dc6c7c711e8dffd5d1f98a to your computer and use it in GitHub Desktop.
Just a gist to explain React Query
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
function ProductList() { | |
const getProducts = async () => { | |
const res = await fetch("https://api.amazon.com/products"); | |
const products = await res.json(); | |
return products; | |
}; | |
const { data, isLoading, isError, error } = useQuery("productList", getProducts); | |
if (isLoading) return "Loading..."; | |
if (isError) return "An error has occurred: " + error.message; | |
return ( | |
<div> | |
<h5>{data.name}</h5> | |
<p>{data.description}</p> | |
<p>$ {data.price}</p> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment