갈푸라떼
갈푸라떼는 개발중
갈푸라떼
전체 방문자
오늘
어제
  • 분류 전체보기 (232)
    • CS (0)
      • CSinfo (0)
    • Frontend (15)
      • HTML,CSS (1)
      • Javascript (2)
      • React (0)
      • React Hook (12)
    • Backend (0)
      • Python (0)
      • Node.js (0)
      • php (0)
    • DB (2)
      • MySQL (2)
      • BigQuery (0)
      • Mongodb (0)
    • Study (186)
      • JavaScript (72)
      • JavaScript(Clean code) (50)
      • Node.js (11)
      • HTML,CSS (13)
      • React (30)
      • TypeScript (10)
      • React-Native (0)
    • Error (2)
      • error (2)
    • Git (22)
      • Git (22)
    • Help Coding (4)
      • Useful websites (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • Github

공지사항

인기 글

태그

  • ECMAScript
  • SPREAD
  • PM2
  • 스코프 체인
  • 심볼
  • 호이스팅
  • 상속
  • 싱글스레드
  • 렉시컬 환경
  • 오버라이딩
  • 실행 컨텍스트
  • 이터러블
  • 네이밍
  • 객체타입
  • symbol
  • Arrow
  • 함수
  • 원시타입
  • this
  • 컴파일러
  • nodemon
  • structure
  • 인터프리터
  • function
  • 프로토타입
  • 정적 레벨
  • class
  • 자바스크립트엔진
  • Babel
  • prototype

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
갈푸라떼

갈푸라떼는 개발중

Study/React

[React_study] styled-components를 이용한 dark/light모드

2022. 7. 20. 00:09

* Theme를 이용한 dark/light모드 만들기

  • index.js파일에 기본 셋팅을 해준다.
  • darkTheme와 lightTheme를 만들어준다.
    • property의 네이밍은 두 객체 모두 동일하게 만들어 주어야 한다.
  • ThemeProvider를 통해서 App을 감싸준다.
  • 그러면 App컴포넌트 모든곳에서 theme이 사용가능해진다.
  • theme이 props로 전달해주는 객체에 따라서 dark/light모드가 변경이 된다.
// index.js

import { ThemeProvider } from "styled-components";

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

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

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

 

* props를 이용하여서 property들을 가져와준다.

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

const Body = styled.div`
  background-color: ${(props) => props.theme.backgroundColor};
`

 

'Study > React' 카테고리의 다른 글

[React_study] useMatch()  (0) 2022.07.24
[React_study] 터미널 / 브라우저 콘솔창에 warning  (0) 2022.06.20
[React_study] reset css 하는 방법 + npm으로 설치  (0) 2022.06.18
[React_study] Redux state가 object/array일 경우 변경 방법  (0) 2022.06.15
[React_study] Redux store의 state 변경  (0) 2022.06.12
    'Study/React' 카테고리의 다른 글
    • [React_study] useMatch()
    • [React_study] 터미널 / 브라우저 콘솔창에 warning
    • [React_study] reset css 하는 방법 + npm으로 설치
    • [React_study] Redux state가 object/array일 경우 변경 방법
    갈푸라떼
    갈푸라떼

    티스토리툴바