๋ํ ์ํ์ ๊ฐ์ ธ์ค๊ธฐ ์ํ ์ฃผ์๋ ์๋์ ๊ฐ๋ค.
[GET] ๋ํ ์ํ ๊ฐ์ ธ์ค๊ธฐ - http://localhost:5000/api/products/featured
๊ทธ๋ฆฌ๊ณ ์ฃผ์ ์ ํ์ 3๊ฐ๊ฐ ๋ค์ด์๋ค.
ํ์ฌ๋ ์์ ๊ฐ์ด ์ฃผ์ ์ ํ๋ค์ด ํ์ ๋๋๋ฐ
useData๋ฅผ ์ฌ์ฉํด์ ๋ฐฑ์๋์์ ์ฃผ์ ์ ํ์ ๋ฐ์์จ ๋ค์์ ProductCard๋ก ๋๊ฒจ์ฃผ๋ฉด ๋๊ฒ ๋ค.
import useData from "../../Hook/useData";
import ProductCard from "../Products/ProductCard";
import ProductCardSkeleton from "../Products/ProductCardSkeleton";
import "./FeaturedProducts.css";
const FeaturedProducts = () => {
const { data: featured, error, isLoading } = useData("/products/featured");
const skeletons = [1, 2, 3];
return (
<section className="featured_products">
<h2>์ฃผ์์ ํ</h2>
<div className="align_center featured_products_list">
{error && <em className="form_error">{error}</em>}
{isLoading && skeletons.map((n) => <ProductCardSkeleton key={n} />)}
{featured &&
featured.map((product) => <ProductCard product={product} />)}
</div>
</section>
);
};
export default FeaturedProducts;
๊ทธ๋ฆฌ๊ณ ํํ์ด์ง์ HeroSection์ ๋ณด๋ฉด ๋ฐ๋ก๊ตฌ๋งค ๋ฒํผ์ด ์๋ค.
์ด ๋ฒํผ์ ํด๋ฆญํ๋ฉด ๊ด๊ณ ํ๊ณ ์๋ ์ํ์ ์์ธ ํ์ด์ง๋ก ์ด๋ํ๊ฒ ๋ง๋ค๊ฑฐ์
HomePage.jsx ์ link๋ฅผ ์์ ํ๋ค.
์ํ ์์ธ๋ณด๊ธฐ๋ /product/์ ํid๊ฐ ๋ค์ด๊ฐ๊ธฐ ๋๋ฌธ์
๊ด๊ณ ํ๊ณ ์๋ ์ ํ์ id๋ฅผ ๋ฃ์ด์คฌ๋ค.
import HeroSection from "./HeroSection";
import iphone from "../../assets/iphone-14-pro.webp";
import mac from "../../assets/mac-system-cut.jfif";
import FeaturedProducts from "./FeaturedProducts";
const HomePage = () => {
return (
<div>
<HeroSection
title="์์ดํฐ 14 ํ๋ก ๊ทธ ์ด์"
subtitle="Experience the power of the latest iPhone 14 with our most Pro camera ever."
link="/product/658234e22518230f6cfd4209"
image={iphone}
/>
<FeaturedProducts />
<HeroSection
title="๊ถ๊ทน์ ์ฅ๋น๋ฅผ ์ธํ
ํ์ธ์"
subtitle="You can add Studio Display and colour-matched Magic accessories to your bag after configure your Mac mini."
link="/product/658234e22518230f6cfd4211"
image={mac}
/>
</div>
);
};
export default HomePage;
๊ทธ๋ฌ๋ฉด ๋ฐ๋ก๊ตฌ๋งค ํด๋ฆญ ์ ํด๋น ์ํ์ ์์ธ๋ณด๊ธฐ ํ์ด์ง๋ก ์ด๋ํ๋ค.