Notice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 에릭 노먼드
- 출처 : 코딩앙마
- https://product.kyobobook.co.kr/detail/S000001952246
- 생코님Redux
- 유틸리티타입은 공식문서 자주 보자
- 출처는 코딩애플
- 쏙쏙 들어오는 함수형 코딩
- 흥달쌤
- 함수형 코딩
- 오종택개발자님
- 이웅모
- 갈길이 멀구나
- 출처 : 한입크기로 잘라먹는 타입스크립트
- 큰돌의 CS책
- 에릭 노이먼
- 쏙쏙들어오는함수형코딩
- 출처는 코딩앙마
- 김영한쌤
- 출처 : https://www.boostcourse.org/
- 로버트 C마틴
- 쏙속 들어오는 함수형코딩
- 나는 flux좋아...
- 리엑트를 다루는 기술
- 고등애플
- 클린코드다시읽기
- 에릭노이먼
- 자바스크립트 딥다이브
- 출처 : 코딩애플
- 쏙쏙 들어오는 함수형코딩
- 출처 : 자바스크립트 딥다이브
Archives
- Today
- Total
폭파할까 말까 고민중인 잡지식 메모장
[React] styled-components쓸때 prop보낼때 본문
//Button.js 여기서 쓴 ${(prop)=>...} 것
import styled, { css } from 'styled-components';
import palette from '../../lib/styles/palette.js';
const StyledButton = styled.button`
...
${(props) =>
props.fullWidth &&
css`
padding: 0.75rem 0 0.75rem 0;
width: 100%;
font-size: 1.125rem;
`}
${(props) =>
props.cyan &&
css`
background: ${palette.cyan[5]};
&:hover {
background: ${palette.cyan[4]};
}
`}
`;
const Button = (props) => <StyledButton {...props} />;
export default Button;
//여기서버튼적용
import Button from './Button';
const ButtonWithMarginTop = styled(Button)`
margin-top: 1rem;
`;
function 여기서버튼적용 ()=>{
return (<ButtonWithMarginTop
cyan={true}
fullWidth={true}
style={{ marginTop: '1rem' }}
>
...
</ButtonWithMarginTop>)
}
"여기서버튼적용"컴포넌트에서 props 보낼때 fullWidth 라고 쓴 값 DOM에도 있다고 소문자로 바꾸래서 바꾸고,
props 보낼때 boolean표기를 ={}안에 말고 =''문자열로 표기하라고 함
아래와 같이 수정하니 에러 메시지 사라쥠
//Button.js 여기서 쓴 ${(prop)=>...} 것
import styled, { css } from 'styled-components';
import palette from '../../lib/styles/palette.js';
const StyledButton = styled.button`
...
${(props) =>
props.fullwidth &&
css`
padding: 0.75rem 0 0.75rem 0;
width: 100%;
font-size: 1.125rem;
`}
${(props) =>
props.cyan &&
css`
background: ${palette.cyan[5]};
&:hover {
background: ${palette.cyan[4]};
}
`}
`;
const Button = (props) => <StyledButton {...props} />;
export default Button;
//여기서버튼적용
import Button from './Button';
const ButtonWithMarginTop = styled(Button)`
margin-top: 1rem;
`;
function 여기서버튼적용 ()=>{
return (
<ButtonWithMarginTop
cyan='true'
fullwidth='true'
style={{ marginTop: '1rem' }}
>
...
</ButtonWithMarginTop>)
}