Skip to content

Instantly share code, notes, and snippets.

@VithuJey
Last active October 21, 2021 15:26
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 VithuJey/d272e969a7dc6c7c711e8dffd5d1f98a to your computer and use it in GitHub Desktop.
Save VithuJey/d272e969a7dc6c7c711e8dffd5d1f98a to your computer and use it in GitHub Desktop.
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