0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

emotionでThemeを書き換える

Posted at

EmotionでThemeを書き換える

実装方法でハマったので備忘録として残しておく。

src/components/MyAppTheme.ts

import { ThemeProvider } from "@emotion/react";
import styled from "@emotion/styled";
import { MyAppTheme } from "./MyAppTheme";

const ThemeButton = styled.button`
  background-color: ${({theme}) => theme.backColor};
  color: ${({theme}) => theme.foreColor};
  padding: ${({theme}) => theme.padding};
`;

export const Buttons = () => {
  return (
    <ThemeProvider theme={MyAppTheme}>
      <ThemeButton >Button</ThemeButton>
    </ThemeProvider>
  );
}

src/App.tsx

import { ThemeProvider } from "@emotion/react";
import styled from "@emotion/styled";
import { MyAppTheme } from "./components/MyAppTheme";

const ThemeButton = styled.button`
  background-color: ${({theme}) => theme.backColor};
  color: ${({theme}) => theme.foreColor};
  padding: ${({theme}) => theme.padding};
`;

export default function App() {
  return (
    <ThemeProvider theme={MyAppTheme}>
      <ThemeButton >Button</ThemeButton>
    </ThemeProvider>
  );
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?