[이은정] 3주차#3
Hidden character warning
Conversation
devHudi
left a comment
There was a problem hiding this comment.
영화를 주제로 개발해주셨군요 ㅎㅎ! 저도 조커 참 재밌게 보았던 기억이 있네요.
지난주 과제 때 보다 훨씬 성장하신 것 같아요 👍
몇가지 수정하면 좋을 만한 점을 코멘트 달아드렸어요. 반영해주셔도 좋고, 참고만 해주셔도 좋습니다 😁
| // const media = [ | ||
| // { img: "/img/B1.jpg", head: "test1" }, | ||
| // { img: "/img/C1.jpg", head: "test2" }, | ||
| // { img: "/img/D1.jpg", head: "test3" }, | ||
| // ]; |
| {/* {media.map((m) => ( | ||
| <MediaCard image={m.img} head={m.head}></MediaCard> | ||
| ))} */} |
| <Wrapper3> | ||
| <Wrapper2> | ||
| <MediaCard image="/img/B1.jpg" head="Joker" /> | ||
| <MediaCard image="/img/C1.jpg" head="Oneday" /> | ||
| <MediaCard image="/img/D1.jpg" head="Eternal Sunshine" /> |
There was a problem hiding this comment.
다른 개발자와 협업을 할 때, Wrapper, Wrapper2, Wrapper3 각각의 컴포넌트의 특성과 차이를 이름만 보고 예상할 수 있을까요? 좋은 컴포넌트 네이밍이란 무엇일까요? 정답은 없습니다 😁
| `; | ||
|
|
||
| const Button = (props) => { | ||
| console.log(props); |
| const StyledImage = styled.img` | ||
| position: relative; | ||
| object-fit: cover; | ||
| width: ${(props) => (props.width ? props.width : "16px")} ; | ||
| height: ${(props) => (props.height ? props.height : "16px")} ; | ||
| `; | ||
|
|
||
| const Image = (props) => { | ||
| return ( | ||
| <StyledImage src={props.Image} width={props.width} height={props.height}> | ||
| {props.children} | ||
| </StyledImage> | ||
| ); | ||
| }; | ||
|
|
||
| export default Image; |
There was a problem hiding this comment.
여기서 Image 컴포넌트는 단순히 props 를 받아 그대로 StyledImage 에게 전달하는 역할만을 하고 있는데요,
| const StyledImage = styled.img` | |
| position: relative; | |
| object-fit: cover; | |
| width: ${(props) => (props.width ? props.width : "16px")} ; | |
| height: ${(props) => (props.height ? props.height : "16px")} ; | |
| `; | |
| const Image = (props) => { | |
| return ( | |
| <StyledImage src={props.Image} width={props.width} height={props.height}> | |
| {props.children} | |
| </StyledImage> | |
| ); | |
| }; | |
| export default Image; | |
| const Image = styled.img` | |
| position: relative; | |
| object-fit: cover; | |
| width: ${(props) => (props.width ? props.width : "16px")} ; | |
| height: ${(props) => (props.height ? props.height : "16px")} ; | |
| `; | |
| export default Image; |
위와 같이 코드를 개선하면 더 가독성이 높아질 수 있겠군요 🧐
| font_size={props.fontSize} | ||
| background_color={props.backgroundColor} | ||
| > | ||
| {" "} |
There was a problem hiding this comment.
피드백 감사합니다!! 4주차에서 활용해서 코드 짜볼께요:)
| font_weight={props.fontWeight} | ||
| font_size={props.fontSize} | ||
| background_color={props.backgroundColor} |
There was a problem hiding this comment.
props의 네이밍 컨벤션이 camelCase가 아니라 snake_case를 사용하고 있군요.
| border-radius: 0.25rem; | ||
| background-color: ${(props) => | ||
| props.backgroundColor ? props.backgroundColor : "white"}; | ||
| color: ${(props) => (props.color ? props.color : "black")}; | ||
| border-color: ${(props) => (props.borderColor ? props.borderColor : "black")}; | ||
| `; |
There was a problem hiding this comment.
기본값을 위해 삼항연산자가 반복적으로 사용되고 있는데요, 아래와 같은 방법으로 코드를 좀 더 축약해볼 수 있을 것 같아요.
AS-IS
color: ${(props) => props.color ? props.color : "#212529"};TO-BE
color: ${(props) => props.color || "#212529"};이를 단축 평가 (Short circuit evaluation) 이라고 합니다. (참고: http://milooy.github.io/TIL/JavaScript/short-circuit.html#%E1%84%8B%E1%85%A8%E1%84%8C%E1%85%A6)
이은정 3주차 완성했습니다:)