인프런 커뮤니티 질문&답변
상품 상세 화면이 나오지 않아요..
작성
·
146
1
상품 상세 화면에서 비동기식 처리로 null 이 끝나고 다음 처리가 되지 않는 것 같아요
이 화면에서 새로고침을 하거나 그냥 기다려도 변하지 않네요 뭐가 문제인것일까요?????
product 의 index.js 함께 첨부합니다.
import { useParams } from "react-router-dom";
import axios from "axios";
import { useEffect, useState } from "react";
function ProductPage() {
const { id } = useParams();
const [product, setProduct] = useState(null);
useEffect(function () {
axios
.get(
"https://a961ad84-b349-455c-9581-09eecba1d299.mock.pstmn.io/products" +
id
)
.then(function (result) {
setProduct(result.data);
})
.catch(function (error) {
console.error(error);
});
}, []);
if (product === null) {
return <h1>상품 정보를 받고 있습니다..</h1>;
}
return (
<div>
<div id="image-box">
<img src={"/" + product.imageUrl} />
</div>
<div id="profile-box">
<img src="/images/images/icons/avatar.png" />
<span>{product.seller}</span>
</div>
<div id="contents-box">
<div id="name">{product.name}</div>
<div id="price">{product.price}원</div>
<div id="description">{product.description}</div>
</div>
</div>
);
}
export default ProductPage;




