首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@情感/反应ThemeProvider不起作用

@情感/反应ThemeProvider不起作用
EN

Stack Overflow用户
提问于 2022-01-24 01:50:01
回答 1查看 621关注 0票数 1

操作系统信息。Macbook (M1 Pro)蒙特利12.1

libs版本信息。反应: 17.0.2,@情感/反应: 11.7.1,@情感/风格: 11.6.0

大家好。我有问题。

当我使用造型组件的时候。它起作用了,但没有情感/风格。为什么“情绪/反应”的ThemeProvider不工作?

这是我的密码。

代码语言:javascript
复制
App.tsx
...
import theme from '.styles/theme';
import { ThemeProvider } from '@emotion/react';
...
<ThemeProvider theme={theme}>
   <Component />
</ThemeProvider>



./styles/theme.ts
...
import { Theme } from '@emotion/react';
const theme: Theme = {
  ...
  color: 'red' //simple test code
};
export default theme;


./components/component.tsx
...
import styled from '@emotion/styled';
const Button = styled.button`
  color: ${(props) => props.color}
`;
const Component: React.FC = () => {
  return <Button />
};
export default Component;
EN

回答 1

Stack Overflow用户

发布于 2022-01-24 05:14:03

我解决了!!只需要熟食模块类型。

(前)

代码语言:javascript
复制
./types/Theme.ts
import '@emotion/react'; // it's important to use ThemeProvider
declare module '@emotion/react' {
  export interface Theme {
    color: string;
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70828179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档