분류
Reactjs
Create React App 시작하기 (4)
본문
import React from 'react';
const CardBox = (props) => {
return(
<div className="card-body">
{props.children}
</div>
)
}
const Image = (props) => {
return(
<img src={props.image} alt="Logo" className="picture">
</img>
)
}
const Name = (props) => {
return(
<div className="name">
{props.name}
</div>
)
}
const Details = (props) => {
return(
<div className="details">
{props.details}
</div>
)
}
const Star = ({ selected=false, onClick=f=>f }) =>
<div className={(selected) ? "star selected" : "star"}
onClick={onClick}>
</div>
const Card = (props) => {
return(
<CardBox>
<div className="inner-body">
<Image image={props.image}/>
<div className="body">
<div className="inner-body">
<Name name={props.name}/>
</div>
<Details details={props.details}/>
<div className="inner-body">
{[...Array(5)].map((n, i) =>
<Star key={i}
selected={i<props.starsSelected}
onClick={() => props.change(props.id, i+1)}
/>)}
</div>
</div>
</div>
</CardBox>
)
}
export { Card }
보시다시피, 우리는 카드 안의 각 요소에 대해 별도의 Stateless 구성 요소를 작성하고 있습니다. 즉, 식당 이름, 세부 정보, 이미지 및 등급 섹션. 그런 다음이 모든 것을 a Card 구성 요소 안에 넣고 기본값으로 내 보냅니다.
- 이전글Create React App 시작하기 (5) 19.08.15
- 다음글Create React App 시작하기 (3) 19.08.15