-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
잘 안되서, 소스 코드를 복붙했더니 해당 에러가 출력됩니다.
22.02.19 16:38 작성 조회수 541
1
ㅇexport default에 오류가 출력되는데 이유를 알려주시면 감사하겠습니다.
답변을 작성해보세요.
0
0
이상민
질문자2022.02.23
터미널에는
ERROR in src/product/index.js
Line 42: Parsing error: 'import' and 'export' may only appear at the top level. (42:0)
라고 출력되며 42번째 줄이 export default ProductPage; 입니다
0
0
이상민
질문자2022.02.22
import { useParams } from "react-router-dom";
import axios from "axios";
import { useEffect, useState } from "react";
import "./index.css"
function ProductPage() {
const { id } = useParams();
const [product, setProduct] = useState(null);
useEffect(function () {
axios
.get(
`https://1a135b44-e524-4168-8a97-42364bfed983.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/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="createdAt">2020년 12월 8일</div>
<div id="description">{product.description} </div>
</div>
</div>
);
}
export default ProductPage;
입니다 !
0
답변 5