Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Let
- Openlayers
- VAR
- const
- input
- htmlFor
- 학습법 #집중력
- FOR
- appendChild
- createtextnode
- createElement
- Append
- boolean
Archives
- Today
- Total
Atomic Habits
styled-components : styled.div` useState ` 본문
import React, { useState } from "react";
import styled from "styled-components";
function Example() {
const [email, setEmail] = useState("");
return (
<ExampleWrap active={email.length}>
<Button>Hello</Button>
<NewButton color="blue">Im new Button</NewButton>
</ExampleWrap>
);
}
const ExampleWrap = styled.div`
background: ${({ active }) => {
if (active) {
return "white";
}
return "#eee";
}};
color: black;
`;
const Button = styled.button`
width: 200px;
padding: 30px;
`;
// Button 컴포넌트 상속
const NewButton = styled.Button`
// NewButton 컴포넌트에 color가는 props가 있으면 그 값 사용, 없으면 'red' 사용
color: ${props => props.color || "red"};
`;
export default Example;
출처 : https://lienkooky.tistory.com/123
'IT > Style(Library)' 카테고리의 다른 글
React. Part2. ch2. 01-2. styled-components (0) | 2021.11.10 |
---|---|
문제 : [object Object] - styled-components (0) | 2021.11.10 |
Comments