๋ฆฌ์กํธ ๊ฐ๋ฐ์ ํ ๋ CSS๋ฅผ ์ ์ฉํ๊ธฐ ์ํด์๋ ๋ฐ๋ก cssํ์ผ์ ๋ง๋ค์ด์ js, jsx ํ์ผ์ importํ๊ฑฐ๋ ์ธ๋ผ์ธ์ผ๋ก ์ง์ ํด์คฌ์ด์ผ ํ์ต๋๋ค. ์ ์์ ๊ฒฝ์ฐ๋ ํ์ผ์ ๊ฐ์๊ฐ ๋์ด๋๊ณ ํด๋์ค ๋ค์์ ์ผ์ผ์ด ๋ถ์ฌ์ค์ผ ๋๋ค๋ ๋ถํธํจ์ด ์๊ณ ํ์์ ๊ฒฝ์ฐ๋ jsx๋ฐฉ์์ผ๋ก css์คํ์ผ์ ์ง์ ํด์ค์ผ ํ๋ค๋ ๋ถํธํจ์ด ๋ฐ๋ฅด์ฃ .
์ด๊ฒ๋ค์ ํด๊ฒฐํด์ฃผ๊ณ ์กฐ๊ธ๋ ๋ฆฌ์กํธ ์ค๋ฝ๊ฒ ์คํ์ผ์ ์ ์ฉํ ์ ์์ผ๋ฉฐ ์ฌ๋ฌ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ๋ค์ ์ ๊ณตํด์ฃผ๋ styled-components๋ฅผ ์๊ฐํฉ๋๋ค.
styled-components ์ค์น
npm install styled-components
js ํ์ผ์ import
import styled from "styled-components";
styled-components ์ฌ์ฉ๋ฒ
const Box = styled.div`
width: 100px;
height: 100px;
background-color: ${props=>props.bgColor}
`
function App() {
return (
<Box/>
);
}
์ด ๋ฐ์ ์ฌ๋ฌ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ๋ค์ด ์์ต๋๋ค.
props, attr, as, nested
'react' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[React] ๋ฆฌ์กํธ์์ TypeScript๋ฅผ ์ธ ๋ ํ์ํ ๊ฒ (feat. useState) (0) | 2023.08.03 |
---|---|
[React] react-query ์ useQuery ์์๋ณด๊ธฐ (0) | 2023.08.01 |
[React] Recoil ์ฌ์ฉ ๋ฐฉ๋ฒ / ๊ณต์๋ฌธ์๋ฅผ ํตํด ์์๋ณด๊ธฐ (0) | 2023.07.26 |
[React] ์ํ๊ด๋ฆฌ์ ํ์์ฑ๊ณผ ๋ฆฌ๋์ค ver 1 (0) | 2023.07.26 |
[React]TIL (0) | 2023.07.18 |