Skip to content

Commit

Permalink
fix: 이미지 로드 실패 시 기본 이미지로 대체하는 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
LMS10 committed Dec 8, 2024
1 parent c30c5c3 commit af422ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/pages/ItemPage/components/ItemDetailsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ function ItemDetailsSection({ item }) {

return (
<SectionContainer>
{item.images && item.images.length > 0 ? (
<ItemImage src={item.images[0]} alt={item.name} />
) : (
<ItemImage src={defaultImage} alt={item.name} />
)}
<ItemImage
src={
item.images && item.images.length > 0 ? item.images[0] : defaultImage
}
alt={item.name}
onError={(e) => (e.target.src = defaultImage)}
/>

<ItemDetailsContainer>
<MainDetails>
Expand Down
15 changes: 10 additions & 5 deletions src/pages/MarketPage/components/AllItemsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ function AllItemsSection() {
<div className="allItemsCardSection">
{itemList?.map((item) => (
<Link to={`/items/${item.id}`} key={item.id} className="itemCard">
{item.images && item.images.length > 0 ? (
<img src={item.images[0]} alt={item.name} className="itemImage" />
) : (
<img src={defaultImage} alt={item.name} className="itemImage" />
)}
<img
src={
item.images && item.images.length > 0
? item.images[0]
: defaultImage
}
alt={item.name}
className="itemImage"
onError={(e) => (e.target.src = defaultImage)}
/>
<h3 className="itemName">{item.name}</h3>
<p className="itemPrice">{item.price.toLocaleString()}</p>
<div className="favoriteCount">
Expand Down
15 changes: 10 additions & 5 deletions src/pages/MarketPage/components/BestItemsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ function BestItemsSection() {
<div className="bestItemsCardSection">
{itemList?.map((item) => (
<Link to={`/items/${item.id}`} key={item.id} className="itemCard">
{item.images && item.images.length > 0 ? (
<img src={item.images[0]} alt={item.name} className="itemImage" />
) : (
<img src={defaultImage} alt={item.name} className="itemImage" />
)}
<img
src={
item.images && item.images.length > 0
? item.images[0]
: defaultImage
}
alt={item.name}
className="itemImage"
onError={(e) => (e.target.src = defaultImage)}
/>
<h3 className="itemName">{item.name}</h3>
<p className="itemPrice">{item.price.toLocaleString()}</p>
<div className="favoriteCount">
Expand Down

0 comments on commit af422ef

Please sign in to comment.