[TIL/React] 2023/08/31
쇼핑하기 페이지 구현 🟠iamge정육각 홈페이지에서 이미지를 추출해 옴!, 객체 형태로 각 이미지를 구성한 다음, shoppingMainImg라는 이름으로 exportdata카테고리 리스트에서는 id, title, image를 객체로 담아 배열화 함!shopping
쇼핑하기 페이지 구현 🟠
1. iamge

정육각 홈페이지에서 이미지를 추출해 옴!, 객체 형태로 각 이미지를 구성한 다음, shoppingMainImg라는 이름으로 export
2. data
import { shoppingMainImg } from "../images";
export const shoppingCategoryList = [
{
id: "1",
title: "돼지",
mainImage: shoppingMainImg.shoppingMainImg1,
},
{
id: "2",
title: "소",
mainImage: shoppingMainImg.shoppingMainImg2,
},
{
id: "3",
title: "닭",
mainImage: shoppingMainImg.shoppingMainImg3,
},
{
id: "4",
title: "수산",
mainImage: shoppingMainImg.shoppingMainImg4,
},
{
id: "5",
title: "밀키트",
mainImage: shoppingMainImg.shoppingMainImg5,
},
{
id: "6",
title: "우유",
mainImage: shoppingMainImg.shoppingMainImg6,
},
{
id: "7",
title: "달걀",
mainImage: shoppingMainImg.shoppingMainImg7,
},
{
id: "8",
title: "이유식",
mainImage: shoppingMainImg.shoppingMainImg8,
},
];
카테고리 리스트에서는 id, title, image를 객체로 담아 배열화 함!
3. shopping page
import React, { useState } from "react";
import styled from "@emotion/styled";
import ComponentWrapper from "../components/common/ComponentWrapper";
import { shoppingCategoryList } from "../data/ShoppingCategoryList";
const ShoppingMainImgWrapper = styled.div`
width: 100%;
display: flex;
justify-content: center;
align-items: center;
`;
const ShoppingMainImg = styled.img`
max-width: 100%;
max-height: 100%;
object-fit: cover;
`;
const ShoppingCategoryButton = styled.button`
background-color: ${(props) => (props.isSelected ? "black" : "#f2f2f2")};
border: none;
color: ${(props) => (props.isSelected ? "white" : "black")};
font-weight: bolder;
width: 100%;
height: 60px;
&:hover {
background-color: black;
color: white;
}
`;
const ShoppingPage = () => {
const [selectedCategory, setSelectedCategory] = useState(null);
const handleShoppingPageViewClick = (category) => {
setSelectedCategory(category);
};
return (
<div>
<ShoppingMainImgWrapper>
{shoppingCategoryList?.map((elem) => (
<ShoppingMainImg
key={elem.id}
src={elem.mainImage}
alt={elem.title}
style={{
display: selectedCategory === elem.id ? "flex" : "none",
}}
/>
))}
</ShoppingMainImgWrapper>
<ComponentWrapper>
<div
style={{
display: "flex",
justifyContent: "space-around",
width: "100%",
marginTop: "100px",
columnGap: "10px",
}}
>
{shoppingCategoryList?.map((elem) => (
<div style={{ width: "100%" }}>
<ShoppingCategoryButton
key={elem.id}
isSelected={selectedCategory === elem.id}
onClick={() => handleShoppingPageViewClick(elem.id)}
>
{elem.title}
</ShoppingCategoryButton>
</div>
))}
</div>
</ComponentWrapper>
</div>
);
};
export default ShoppingPage;
구현하는데 집중해서 코드가 많이 조잡하다!
4. 현재 모습


회고 🔵

만학도의 개강은 너무도 두렵다...! 근데 어쩔건데? 원민관 너가 뭘 할 수 있는데? 8월도 고생 많았다!
More to read
Amazon VPC Architecture 이해하기
새로운 프로젝트를 기획하며, 개발에서 무엇을 가장 먼저 고민해야 하는지 다시 돌아보게 되었습니다.한때는 프론트엔드가 모든 설계의 출발점이라고 믿었습니다. 유저가 무엇을 보고, 어떤 흐름에서 머무르고 이탈하는지에 대한 이해 없이 서비스를 만든다는 건 불가능하다고 생각했기
'원사이트'프론트엔드 관점으로 알고리즘 이해하기
오랜만에 방법론에 관한 글을 쓰게 되었습니다. 최근 상황은 이렇습니다. SSAFY에서는 하루에 엄청난 양의 알고리즘 문제들을 과제로 수행하게 됩니다. 그 과정에서, '구현력'이 매우 떨어진다는 생각이 들었습니다. 완전히 어려운 문제라면 '아쉬움'이라는 감정조차 느끼지
SubnetVPC 설계의 시작: IP와 Subnet
반복되는 루틴 속에서 얻은 안정감을 발판 삼아, 이제는 기술적 스펙트럼을 넓히기 위한 개인 프로젝트에 착수하고자 합니다.이번 프로젝트의 목표는 단순한 포트폴리오 구축을 넘어, 실제 서비스 수준의 블로그 시스템 구현과 다국어 처리 적용 등 실무에 가까운 역량을 한 단계