으아앙악 두개재!!!!!!!!!!!!
<Home />
컴포넌트에서 <Movie />
컴포넌트를 보여줬던 것 처럼,<Detail />
컴포넌트에서 보여줄 MovieDetail
컴포넌트를 만들었다.<Detail />
에서 prop 으로 받아 사용해주면 된다.// - Detail.js
...
return (
<div>
{loading ? (
<LoadingH1 />
) : (
<div>
<MovieDetail
key={detail.id}
id={detail.id}
coverImg={detail.medium_cover_image}
title={detail.title}
year={detail.year}
genres={detail.genres}
runtime={detail.runtime}
rating={detail.rating}
desc={detail.description_full}
backImg={detail.background_image}
/>
</div>
)}
</div>
);
}
export default Detail;
// -MovieDetail.js
function MovieDetail({
coverImg,
title,
year,
genres,
runtime,
rating,
desc,
backImg,
}) {
return (
<div>
{/* header */}
<div>
<img src={backImg} />
{/* section_*/}
<div>
<img src={coverImg} alt={coverImg} />
<div>
<div>
{title} ({year})
</div>
<div>
{genres &&
genres.map((gen) => (
<pkey={gen}>
{gen}
</p>
))}
</div>
<p>
🕐 {runtime ? `${runtime} Minute` : 'None'} | ⭐ {rating}
</p>
<div>
{desc.length > 230 ? `${desc.slice(0, 230)}...` : desc}
</div>
</div>
</div>
</div>
</div>
);
}
MovieDetail
의 propTypes 타입도 정해주자.MovieDetail.propTypes = {
coverImg: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
year: PropTypes.number.isRequired,
genres: PropTypes.arrayOf(PropTypes.string).isRequired,
runtime: PropTypes.number,
rating: PropTypes.number,
desc: PropTypes.string,
};
isRequired
를 따로 주지 않았다.<h1>Loading ...</h1>
을 보여주고 있었던 것이 생각나 하나의 컴포넌트로 제작해주기로한다.// -Loading.js
import loaStyle from '../loading.module.css';
function LoadingH1() {
return <div className={loaStyle.h1}>Loading...</div>;
}
export default LoadingH1;
// - Detail.js
...
return (
<div>
{loading ? (
<LoadingH1 /> <<<-----
) : (
<div>
...
<Movie />
, <MovieDetail />
컴포넌트에도gooooooood >_<