Illie
styled-componont에서 props 사용하기 본문
개요
props로 넘어오는 값이 무엇이냐에 따라 styled-component를 활용하여 색깔을 바꾸려고 한다
본문
아래와 같이 값을 props로 받는 태그가 있다
<STATE color={data.state}>{data.state}</STATE>
styled components를 활용하여 props의 값에 따라 색깔을 바꿔주고 싶다
그럴 때엔 아래와 같이 props를 받으면 된다
const State = styled.Text`
${props => {
switch(props.color) {
case '안녕':
return css`
color: red;
`;
case '하이':
return css`
color: orange;
`;
case '헬로우':
return css`
color: yellow
`;
default:
return css`
color: #000;
`;
}
}}
`;
결론
...!
'REACT || REACT NATIVE' 카테고리의 다른 글
RN. 키보드에서 enter을 눌렀을 때, onPress 함수 호출 (0) | 2022.08.28 |
---|---|
React Native. Props로 컴포넌트 스타일을 커스터마이징하기 (0) | 2022.08.07 |
React. useReducer (상태관리) (0) | 2022.08.02 |
REACT. JSX 문법 3/3 (0) | 2022.05.01 |
REACT. JSX문법 2/3 (0) | 2022.05.01 |
Comments