HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🧚
[1기]최종 프로젝트 데브코스
/
[팀7] 뿡치와 삼촌들 - Devnity
[팀7] 뿡치와 삼촌들 - Devnity
/
📘
프론트엔드 공간
/
🧑‍🎓
Today We Learned
/
emotion theme 타입 지정하는 방법
emotion theme 타입 지정하는 방법
emotion theme 타입 지정하는 방법

emotion theme 타입 지정하는 방법

생성일
Dec 3, 2021 06:46 AM
기록자
Jay Mincheol Cho
해결 여부
해결 여부
속성
카테고리

문제 상황

아래와 같이 프로젝트 내에서 공통으로 사용하는 스타일 값을 theme으로 만들어두고 emotion의 ThemeProvider를 이용해서 import 없이 스타일 값을 사용하도록 설정하려고 한다.
theme.ts:
export default { colors: { primary: "#ffb266", fontColor: "#4d5256", disabled: "#c0c0c0", black: "#000", white: "#fff", }, }
App.tsx:
import { ThemeProvider } from "@emotion/react"; import styled from "@emotion/styled"; import GlobalTheme from "./assets/theme"; const Wrapper = styled.div` width: 100px; height: 100px; background-color: ${({ theme }) => theme.colors.primary}; `; const App = () => { return ( <ThemeProvider theme={GlobalTheme}> <Wrapper> <App /> </Wrapper> </ThemeProvider> ); }; export default App;
notion image

해결 방법

types/emotion.d.ts:
import "@emotion/react"; import { ITheme } from "../assets/theme"; declare module "@emotion/react" { export interface Theme extends ITheme {} }
notion image

See also

  • emotion - Define a theme with TypeScript