小编The*_*LDR的帖子

如何在 React 和 Typescript 中使用 Material UI 自定义主题

使用这个工具https://react-theming.github.io/create-mui-theme/ 我得到一个 js 文件和一个 json 文件,如上述主题生成器页面中提到的相应路径:

// src/ui/theme/index.js
/* src/ui/theme/theme.json */
Run Code Online (Sandbox Code Playgroud)

现在,当我将文件扩展名留给 js 时,它们可以正常工作。一旦我尝试使用 js 作为 tsx 文件,编辑器就会开始抱怨。我也通过 tsconfig 文件中的 CRA Typescript 完成了所有必要的设置。此页面的必要配置https://material-ui.com/guides/typescript/

当我尝试这个时它不起作用,如果我遗漏了什么有什么想法吗?

// My amended index.tsx file

import { createMuiTheme } from '@material-ui/core/styles';

const palette = {
  primary: { main: '#3f51b5' },
  secondary: { main: '#f50057' }
};
const themeName = 'San Marino Razzmatazz Sugar Gliders';

export default createMuiTheme({ palette, themeName });
Run Code Online (Sandbox Code Playgroud)

我也没有触及 theme.json 。我还在学习抱歉,如果这是一个界面问题以及如何使用它,有什么想法吗?谢谢!

javascript typescript reactjs material-ui create-react-app

7
推荐指数
4
解决办法
7440
查看次数