Skip to content

Instantly share code, notes, and snippets.

@VithuJey
Last active Oct 21, 2021
Embed
What would you like to do?
Just a gist to explain React Query
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