小编use*_*390的帖子

React Typescript:属性“body”不存在类型“DefaultTheme”

我是 React 和 Typescript 的新手,我正在尝试将暗模式添加到我的项目中,我创建了 globalStyle 组件、Themes 组件并使用 Themeprovider。

我的 globalStyle 组件遇到问题:属性“body”不存在类型“DefaultTheme”

我的 globalStyles.tsx 代码如下:

import { createGlobalStyle} from "styled-components"
export const GlobalStyles = createGlobalStyle`
  body {
    background: ${({ theme }) => theme.body};
    color: ${({ theme }) => theme.text};
    font-family: Tahoma, Helvetica, Arial, Roboto, sans-serif;
    transition: all 0.50s linear;
  }`
Run Code Online (Sandbox Code Playgroud)

我的主题.tsx:

export const lightTheme = {
    body: '#FFF',
    text: '#363537',
    background: '#363537',
}
export const darkTheme = {
    body: '#363537',
    text: '#FAFAFA',
    background: '#999',
}
Run Code Online (Sandbox Code Playgroud)

以及我在 App.tsx 上的 Themeprovider 代码: …

javascript typescript reactjs styled-components

8
推荐指数
1
解决办法
1万
查看次数