๐ŸŽจ Styled Components ์˜ ์œ ์šฉ์„ฑ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐ

๊น€๋ฏผ์ค€ยท2024๋…„ 11์›” 16์ผ

CSS

๋ชฉ๋ก ๋ณด๊ธฐ
4/4

๐Ÿ‘‰ without Styled Components

์•Œ์•„๋ณด๊ธฐ ์ „์—
Styled Components์—†์ด css๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์ž

function App() {
  return (
    <div style={{ display: "flex" }}>
      <div style={{ backgroundColor: "teal", width: 100, height: 100 }}></div>
      <div style={{ backgroundColor: "tomato", width: 100, height: 100 }}></div>
    </div>
  );
}

์ด ๋ฐฉ์‹์€ ๋จผ์ € div๋ฅผ ์ƒ์„ฑํ•œ ๋‹ค์Œ
์Šคํƒ€์ผ์„ ์ ์šฉ์‹œ์ผฐ๋‹ค
๊ทธ๋ฆฌ๊ณ  ๊ฐ๊ฐ div ๋ฅผ ๋“ค์—ฌ๋‹ค๋ด์•ผ์ง€๋งŒ,
์–ด๋–ค ์—ญํ• ๊ณผ css๊ฐ€ ์ ์šฉ๋˜์—ˆ๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค

๐Ÿ‘‰ Styled Components ๊ธฐ๋ณธ์„ธํŒ…

๋จผ์ € ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•ด์ค€๋‹ค

npm i styled-components

๋‹ค์Œ, import๋ฅผ ํ•ด์„œ ์‚ฌ์šฉํ•  ์ค€๋น„๋ฅผ ํ•œ๋‹ค

import styled from "Styled-components"

Styled Components๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด,
๋ชจ๋“  ์Šคํƒ€์ผ์€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ด์ „์— ๋ฏธ๋ฆฌ ์ปดํฌ๋„ŒํŠธ์— ํฌํ•จ์ด ๋œ๋‹ค.

๐ŸŽˆ ์‚ฌ์šฉ๋ฐฉ๋ฒ•

const ์ž‘๋ช… = styled.ํƒœ๊ทธ ` css `

์œ„ ๋ฐฉ์‹์„ ํ† ๋Œ€๋กœ
์ด์ „์— ์ž‘์„ฑํ•œ ๊ธฐ๋ณธ css ๋ฅผ ๋Œ€์ฒดํ•ด๋ณด์ž

// <div style={{ display: "flex" }}>
const Father = styled.div`
  display: flex;
`;


// <div style={{ backgroundColor: "teal", width: 100, height: 100 }}></div>
const BoxOne = styled.div`
  background-color: teal;
  width: 100px;
  height: 100px;
`;


const BoxTwo = styled.div`
  background-color: tomato;
  width: 100px;
  height: 100px;
`;

const Text = styled.div`
  color: white;
`;


function App() {
  return (
    <Father>
      <BoxOne>
        <Text> Hello</Text>
      </BoxOne>
      <BoxTwo />
    </Father>
  );
}

์ด ๋ฐฉ์‹์˜ ์žฅ์ 

  • ์ฝ”๋“œ๋ถ€๋ถ„์ด ์•„์ฃผ ๊น”๋”ํ•ด์ง€๋Š” ์ 
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฐฉ์‹์ด ์•„๋‹Œ, css ๋ฐฉ์‹์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๋Š” ์ 
  • ์žฌ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์  ์ด๋‹ค

๐ŸŽˆ props ์žฌ์‚ฌ์šฉ

ํ˜„์žฌ ๋ฐ•์Šค 1๊ณผ 2 ๋Š” ์ƒ‰์ƒ๋งŒ ๋‹ค๋ฅด๋‹ค
ํ•˜์ง€๋งŒ ๋™์ผ ์ฝ”๋“œ๋ฅผ ์ƒ‰์ƒ ๋•Œ๋ฌธ์— 2๋ฒˆ ์ ๊ณ  ์žˆ๋‹ค

์ด๋Ÿฐ ๊ฒฝ์šฐ์—๋Š”, props ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ปดํฌ๋„ŒํŠธ ํ™•์žฅ์ด ๊ฐ€๋Šฅํ•˜๋‹ค

์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ ์„ ์–ธ ๋ถ€๋ถ„์ด ์•„๋‹Œ,
์‚ฌ์šฉ ๋ถ€๋ถ„์—์„œ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•ด์ฃผ๋Š” ๋ฐฉ์‹์ด๋‹ค

๋จผ์ € ์„ ์–ธ ๋ถ€๋ถ„์—์„œ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ์€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ด์ฃผ๊ณ 
ํ˜ธ์ถœ ๋ถ€๋ถ„์—์„œ ๋ณ€์ˆ˜๋ฅผ props๋กœ ์ „๋‹ฌํ•ด์ฃผ๋ฉด ๋œ๋‹ค

const Box = styled.div`
  background-color: ${(props) => props.bgColor};
  width: 100px;
  height: 100px;
`;

function App() {
  return (
    <Father>
      <Box bgColor="teal" />
      <Box bgColor="tomato" />
    </Father>
  );
}

๐ŸŽˆ ์ปดํฌ๋„ŒํŠธ ์žฌ์‚ฌ์šฉ

๋งŒ์•ฝ Box ์™€ ๋™์ผํ•œ ์Šคํƒ€์ผ์„ ๊ฐ€์ง„ ์›์„ ๋งŒ๋“ค๊ณ  ์‹ถ์œผ๋ฉด ์–ด๋–ป๊ฒŒ ํ• ๊นŒ?
ํ•˜๋‚˜ ๊ทธ๋Œ€๋กœ ๋งŒ๋“ค๋ฉด ๊ฐ„๋‹จํ•˜์ง€๋งŒ,
์ฝ”๋“œ๊ฐ€ ์ค‘๋ณต๋˜๊ณ  ์žˆ๋‹ค

const Box = styled.div`
  background-color: ${(props) => props.bgColor};
  width: 100px;
  height: 100px;
`;

const Circle = styled.div`
  background-color: ${(props) => props.bgColor};
  width: 100px;
  height: 100px;
  border-radius: 50px;
`;

์ด ๋•Œ ์‚ฌ์šฉ๊ฐ€๋Šฅ ํ•œ ๋ฐฉ์‹์ด
์Šคํƒ€์ผ ์ปดํฌ๋„ŒํŠธ ์ž์ฒด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ํ˜•์‹์ด๋‹ค
์œ„์—์„œ div ๋ฅผ ๋ถˆ๋Ÿฌ ์˜ค๋Š” ๋Œ€์‹ ,
๋งŒ๋“ค์–ด ๋†“์€ ์Šคํƒ€์ผ ์ปดํฌ๋„ŒํŠธ ์ž์ฒด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณ , css๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค

const Circle = styled(Box)`
  border-radius: 50px;
`;

<Circle bgColor="tomato" />

๐Ÿ“Œ ์™„์„ฑ๋ณธ

import styled from "styled-components";

const Father = styled.div`
  display: flex;
`;

const Box = styled.div`
  background-color: ${(props) => props.bgColor};
  width: 100px;
  height: 100px;
`;

const Circle = styled(Box)`
  border-radius: 50px;
`;

// const BoxTwo = styled.div`
//   background-color: tomato;
//   width: 100px;
//   height: 100px;
// `;

const Text = styled.div`
  color: white;
`;

export default function StyleComponents() {
  return (
    <Father>
      <Box bgColor="teal" />
      <Box bgColor="tomato" />
      {/* <BoxTwo /> */}
      <Circle bgColor="yellow">
        <Text>Hello</Text>
      </Circle>
    </Father>
  );
}

๐Ÿ‘‰ as๋กœ ํƒœ๊ทธ ๋ณ€๊ฒฝ

const Btn = styled.button`
  color: white;
  background-color: tomato;
  border: 0;
  border-radius: 15px;
`;

  return (
    <Father>
      <Btn>Login </Btn>
      <Btn>Logout </Btn>
    </Father>
  );

์Šคํƒ€์ผ์„ ์ž…ํžŒ ๋ฒ„ํŠผ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด ๋†“์•˜๋‹ค
๊ทธ๋Ÿฐ๋ฐ ๊ฐ‘์ž๊ธฐ
์Šคํƒ€์ผ์€ ๋™์ผํ•˜๊ฒŒ ์œ ์ง€ํ•˜๋ฉด์„œ,
๋‹ค๋ฅธ ํƒœ๊ทธ, (div, Link ๋“ฑ๋“ฑ) ์ด ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์œผ๋ฉด ์–ด๋–ป๊ฒŒ ํ• ๊นŒ??

์ด ๋•Œ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ as props์ด๋‹ค
as๋ฅผ ํ†ตํ•ด์„œ ํƒœ๊ทธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋ฉด ํ•ด๋‹น ํƒœ๊ทธ๋กœ ๋ณ€๊ฒฝ์ด ๋œ๋‹ค
a๋งํฌ๋ฅผ as๋กœ ๋ณด๋‚ด์ฃผ๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ž

  return (
    <Father>
      <Btn>Login </Btn>
      <Btn as="a" href="/">Logout </Btn>
    </Father>
  );

buttonํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ,
as๋ฅผ ํ†ตํ•ด์„œ aํƒœ๊ทธ๋กœ ๊ฐ„ํŽธํ•˜๊ฒŒ ๋ณ€๊ฒฝํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค.
aํƒœ๊ทธ๋‹ˆ๊นŒ ์ด๋™๊ฒฝ๋กœ๋„ ๋ฐ”๋กœ ์จ์ฃผ๋ฉด๋œ๋‹ค

๐Ÿ‘‰ ์†์„ฑ๊ฐ’ ์„ค์ • - attrs

const Input = styled.input`
  background-color: tomato;
`;

function App() {
  return (
    <Father as="header">
      <Input required/>
      <Input required/>
      <Input required/>
      <Input required/>
    </Father>
  );
}

๋ชจ๋“  input์— required ๋ผ๋Š” ์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ๋‹ค
๊ฐ๊ฐ์˜ input์— ๋„ฃ์–ด์ฃผ๋ฉด ๊ฐ„๋‹จํ•˜์ง€๋งŒ, ์ด๊ฑด ๊ฐœ๋ฐœ์ž ์Šค๋Ÿฝ์ง€ ๋ชปํ•˜๋‹ค

attrs ๋ฅผ ํ™œ์šฉํ•˜๋ฉด,
ํƒœ๊ทธ๋กœ ์ „๋‹ฌ๋  ์†์„ฑ์„ ๊ฐ€์ง„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค

const Input = styled.input.attrs({ required: true, minLength: 10 })`
  background-color: tomato;
`;

function App() {
  return (
    <Father as="header">
      <Input />
      <Input />
      <Input />
      <Input />
    </Father>
  );
}

์ด๋ ‡๊ฒŒ ๊ฐ์ฒด๋ฅผ ์„ค์ •ํ•ด์ฃผ๋ฉด ์œ„์—์„œ ์„ค์ •ํ•œ required๊ฐ€ ์ „๋ถ€ ๋™์ผํ•˜๊ฒŒ ๋“ค์–ด๊ฐ„๋‹ค
, ๋ฅผ ํ†ตํ•ด์„œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์†์„ฑ์„ ์ถ”๊ฐ€ํ• ์ˆ˜๋„ ์žˆ๋‹ค

๐Ÿ‘‰ ์• ๋‹ˆ๋ฉ”์ด์…˜

์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ์—์„œ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์‚ฌ์šฉํ•˜๋Ÿฌ๋ฉด
๋จผ์ € keyframes ๋ฅผ import ํ•ด์™€์•ผํ•œ๋‹ค

import { keyframes } from "styled-components"

๋‹ค์Œ, ๋ฐ–์—์„œ animation ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค

const animation = keyframes`
	// css ์ž‘์„ฑ
`

์•ˆ์—๋‹ค๊ฐ€ ๊ธฐ๋ณธ css ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ฃผ๋ฉด ๋œ๋‹ค

const animation = keyframes`
    from {
        transform: rotate(0);
    }
    to {
        transform: rotate(360);
    }
`

๊ทธ๋ฆฌ๊ณ  ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ์—
์Šคํƒ€์ผ๋กœ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค

const Box = styled.div`
  width: 200px;
  height: 200px;
  background-color: tomato;
  animation: ${rotationAnimation} 1s linear infinite;
`;

๐Ÿ“Œ ์™„์„ฑ๋ณธ

import styled, { keyframes } from "styled-components";

const rotationAnimation = keyframes`
    0% {
        transform: rotate(0deg);
        border-radius: 0px;
    }
    50% {
        transform: rotate(360deg);
        border-radius: 100px;
    }
    100% {
        transform: rotate(0deg);
        border-radius: 0px;
    }
`;

const Box = styled.div`
  width: 200px;
  height: 200px;
  background-color: tomato;
  animation: ${rotationAnimation} 1s linear infinite;
`;

export default function AnimationBox() {
  return (
    <div>
      <Box />
    </div>
  );
}

๐ŸŽˆ selector

      <Box>
        <span>๐Ÿ˜ข</span>
      </Box>

์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ ์•ˆ์— ๊ทธ๋ƒฅ ํƒœ๊ทธ๊ฐ€ ๋“ค์–ด์žˆ๋‹ค
๊ทธ๋ƒฅ ํƒœ๊ทธ๋ฅผ ์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ์—์„œ
selector ๋ฌธ๋ฒ•์œผ๋กœ ์„ ํƒํ•ด์„œ
์Šคํƒ€์ผ ์ง€์ •์ด ๊ฐ€๋Šฅํ•˜๋‹ค

์ฆ‰, ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๋ฅผ ์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ๋กœ ๋งŒ๋“ค ํ•„์š”๊ฐ€ ์—†๋Š” ์…ˆ์ด๋‹ค

const Box = styled.div`
  ...
  justify-content: center;
  align-items: center;
  span {
    font-size: 36px;
  }
`;

๐Ÿ“ & - pseudo selector

&:active {
  opacity: 0%;
}

selector ์—์„œ
span:hover ๊ฐ™์€ ๊ฒƒ์„ ๋” ์‰ฝ๊ฒŒ ์ ์šฉ์‹œ์ผœ์ฃผ๋Š” ๋ฌธ๋ฒ•์ด๋‹ค
span:hover = &:hover

const Box = styled.div`
  ...
  align-items: center;
  span {
    font-size: 36px;
    &:hover {
      font-size: 50px;
    }
    &:active {
      opacity: 0%;
    }
  }
`;

๐Ÿ“Œ ์™„์„ฑ๋ณธ

import styled, { keyframes } from "styled-components";

const rotationAnimation = keyframes`
    0% {
        transform: rotate(0deg);
        border-radius: 0px;
    }
    50% {
        transform: rotate(360deg);
        border-radius: 100px;
    }
    100% {
        transform: rotate(0deg);
        border-radius: 0px;
    }
`;

const Box = styled.div`
  width: 200px;
  height: 200px;
  background-color: tomato;
  animation: ${rotationAnimation} 1s linear infinite;
  display: flex;
  justify-content: center;
  align-items: center;
  span {
    font-size: 36px;
    &:hover {
      font-size: 50px;
    }
    &:active {
      opacity: 0%;
    }
  }
`;

export default function AnimationBox() {
  return (
    <div>
      <Box>
        <span>๐Ÿ˜ข</span>
      </Box>
    </div>
  );
}

๐Ÿ‘‰ ํƒœ๊ทธ๋„ค์ž„ ์˜์กด ํ•ด๊ฒฐ

ํ˜„์žฌ spanํƒœ๊ทธ๋กœ ์ฝ”๋”ฉํ•ด๋†“์•˜๋‹ค
๊ทธ๋Ÿผ ๋ฆฌํ„ด ๋ถ€๋ถ„์—์„œ span ์„ pํƒœ๊ทธ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค๋ฉด
์œ„์—์„œ selectํ•ด๋†“์€ ๊ฒŒ ๋ณ€๊ฒฝ๋˜์–ด ์•„๋ฌด๋Ÿฐ css๋„ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค
์ฆ‰, select ๋ถ€๋ถ„์„ ๋‹ค์‹œ p๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์–ด ๋งž์ถฐ์ค˜์•ผ์ง€ ์ ์šฉ์ด ๋œ๋‹ค

์ด๋Ÿฐ ๊ฒฝ์šฐ,
ํ•˜๋‚˜์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋„ฃ์–ด๋ฒ„๋ฆฌ๋ฉด ๋œ๋‹ค
๊ทธ๋ฆฌ๊ณ  ์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ์—์„œ๋Š”
span ์ž๋ฆฌ์—
${์ƒˆ๋กœ๋งŒ๋“ ์ปดํฌ๋„ŒํŠธ๋ช…} ์„ ๋„ฃ์–ด์„œ select ํ•ด์ฃผ๋ฉด ๋œ๋‹ค
๊ทธ๋Ÿฌ๋ฉด, ํ•ด๋‹น ํƒœ๊ทธ๊ฐ€ span ์ด๊ฑด p์ด๊ฑด ์ •์ƒ์ž‘๋™๋œ๋‹ค

const Emoji = styled.span`
	font-size : 36px
`

const Box = styled.div`
  ...
  align-items: center;
  
  ${Emoji} {
    &:hover {
      font-size: 50px;
    }
    &:active {
      opacity: 0%;
    }
  }
`;

export default function AnimationBox() {
  return (
    <div>
      <Box>
        <Emoji>๐Ÿ˜ข</Emoji>   ๐Ÿ“Œ ์ ์šฉ
      </Box>
      
        <Emoji>๐Ÿ”ฅ</Emoji>   ๐Ÿ“Œ ๋ฏธ์ ์šฉ
    </div>
  );
}

Emoji ์ปดํฌ๋„ŒํŠธ์˜ hover ์Šคํƒ€์ผ์€
๋ฐ˜๋“œ์‹œ box ์Šคํƒ€์ผ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ๋งŒ ์ ์šฉ์ด ๋œ๋‹ค
select๋กœ ์ฐ์–ด๋†“์•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค

๋”ฐ๋ผ์„œ ์œ„ ์ฝ”๋“œ์˜ ๋‘๋ฒˆ์งธ ์ด๋ชจ์ง€๋Š”
36px์„ ๊ฐ€์ง€์ง€๋งŒ, hover๋Š” ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค

๐Ÿ‘‰ themes - ๋‹คํฌ๋ชจ๋“œ

๋‹คํฌ๋ชจ๋“œ์—์„œ ํ•„์š”ํ•œ ๊ฒƒ์€ ๋‘๊ฐ€์ง€ ์ด๋‹ค

  • theme
  • local East Management

์ด ์ค‘, ์ฒซ๋ฒˆ์งธ์ธ theme์„ ์ž์„ธํžˆ ์•Œ์•„๋ณด์ž

theme?

  • ๋ชจ๋“  ์ƒ‰์ƒ๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ•˜๋‚˜์˜ ๊ฐ์ฒด

theme provider

๊ฐ€์žฅ ๋จผ์ € theme provider ๋ฅผ indexํŒŒ์ผ์—์„œ importํ•ด์ค€๋‹ค
๊ทธ๋ฆฌ๊ณ  App ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ์‹ธ์ค€๋‹ค

๊ทธ๋ฆฌ๊ณ  ์ƒ‰์ƒ์„ props ๋กœ ๋‚ด๋ ค์ค€๋‹ค

//index.js  or main.js(in vite)

import { ThemeProvider } from "styled-components";

const darkTheme = {
  textColor: "whitesmoke",
  backgroundColor: "#111"
};

const lightTheme = {
  textColor: "#111",
  backgroundColor: "whitesmoke",
};


createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <ThemeProvider theme={darkTheme}>
      <App />
    </ThemeProvider>
  </StrictMode>
);

ํ˜„์žฌ ThemeProvider ์— ์ƒ‰์ƒ์„ ๋„ฃ์–ด์คฌ๊ธฐ ๋•Œ๋ฌธ์—
App ์— ์žˆ๋Š” ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๋“ค์ด ํ•ด๋‹น ์ƒ‰์ƒ์— ์ ‘๊ทผ ํ•  ์ˆ˜ ์žˆ๋‹ค
์ฆ‰, ์œ„์—์„œ ์ง€์ •ํ•œ theme ๊ฐ์ฒด์˜
textColor ๊ฐ’๊ณผ
backgroundColor ๊ฐ’์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•ด์ง„๊ฒƒ์ด๋‹ค
(์ด๊ฑด ์ž‘๋ช…์ด๋ผ ์•„๋ฌด๊ฑฐ๋‚˜ ๊ฐ€๋Šฅ)

// App.js

const Title = styled.h1`
	color : ${props => props.theme.textColor}
`

const Wrapper = styled.div`
	background-color : ${props => props.theme.backgroundColor}
`

์ด์ œ ๋ชจ๋“œ ๋ณ€๊ฒฝ์„ ํ•ด์ฃผ๊ณ  ์‹ถ์œผ๋ฉด

<ThemeProvider theme={darkTheme}> ์ด ๋ถ€๋ถ„์˜ props๋ฅผ
์œ„์—์„œ ์„ ์–ธํ•œ lightTheme์œผ๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋œ๋‹ค
์—ฌ๊ธฐ์„œ ์กฐ์‹ฌํ•ด์•ผํ•  ์ ์ด
๋ฐ˜๋“œ์‹œ ๋‘ ํ…Œ๋งˆ์˜ ํ”„๋กœํผํ‹ฐ ์ž‘๋ช…์ด ๋™์ผํ•ด์•ผํ•œ๋‹ค๋Š” ์ ์ด๋‹ค

0๊ฐœ์˜ ๋Œ“๊ธ€