Created
November 29, 2021 07:22
-
-
Save vedovelli/51d96915f8cd82e6278a3445bc5cad8a to your computer and use it in GitHub Desktop.
Products.js
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 { http } from "../../service/api"; | |
import { Card } from "./Card"; | |
import { Header, Spinner } from "../../components"; | |
import { useQuery } from "react-query"; | |
export default function Products() { | |
const { isLoading, isError, data } = useQuery( | |
"todos", | |
() => http.get("/products").then(({ data }) => data.products) // http container baseURL with `/api` | |
); | |
if (isLoading) return <Spinner message="Loading Products" variant="orange" />; | |
if (isError) return <p>Error</p>; | |
return ( | |
<> | |
<Header>Products</Header> | |
<div className="mt-6 grid grid-cols-1 gap-y-10 gap-x-6 sm:grid-cols-2 lg:grid-cols-4 xl:gap-x-8"> | |
{data.map((product) => ( | |
<Card product={product} key={product.id} /> | |
))} | |
</div> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment