From 7ac5c0dc1cd54d2916be860be79842ab0ee4db32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=8A=B9=EC=84=9D?= Date: Sun, 8 Dec 2024 23:56:32 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DetailBtm.jsx | 43 ++++---------------------- src/components/DetailTop.jsx | 56 ++++++++-------------------------- src/components/ProfileBox.css | 7 +++++ src/components/ProfileBox.jsx | 21 +++++++++++++ src/hooks/useApi.jsx | 25 +++++++++++++++ src/hooks/useDate.jsx | 11 +++++++ src/page/ProductDetailPage.css | 21 ++++--------- 7 files changed, 88 insertions(+), 96 deletions(-) create mode 100644 src/components/ProfileBox.css create mode 100644 src/components/ProfileBox.jsx create mode 100644 src/hooks/useApi.jsx create mode 100644 src/hooks/useDate.jsx diff --git a/src/components/DetailBtm.jsx b/src/components/DetailBtm.jsx index 174c3d6a9..2075162d2 100644 --- a/src/components/DetailBtm.jsx +++ b/src/components/DetailBtm.jsx @@ -1,16 +1,12 @@ import menuIcon from "./../assets/menu_dot.svg"; -import profileIcon from "./../assets/icon_profile.png"; -import React, { useEffect, useState } from "react"; -import axios from "axios"; +import React, { useState } from "react"; +import useApi from "./../hooks/useApi"; +import ProfileBox from "./ProfileBox"; const DetailBtm = ({ id }) => { - const [comment, setComment] = useState([]); const [commentMenu, setCommentMenu] = useState(null); const [textValue, setTextValue] = useState(""); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - const handleTextChange = (e) => { setTextValue(e.target.value); }; @@ -19,19 +15,7 @@ const DetailBtm = ({ id }) => { setCommentMenu(commentMenu === id ? null : id); }; - useEffect(() => { - const fetchProduct = async () => { - try { - const response = await axios.get(`https://panda-market-api.vercel.app/products/${id}/comments?limit=10`); - setComment(response.data.list); - } catch (error) { - setError(error); - } finally { - setLoading(false); - } - }; - fetchProduct(); - }, [id]); + const { data, loading, error } = useApi(`https://panda-market-api.vercel.app/products/${id}/comments?limit=10`); if (loading) { return
Loading...
; @@ -59,14 +43,7 @@ const DetailBtm = ({ id }) => {