在Material-UI中使用自定义主题时不建议使用的字体警告 [英] Deprecated typography warning when using custom theme in Material-UI

查看:138
本文介绍了在Material-UI中使用自定义主题时不建议使用的字体警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码中,我在Material-UI中使用自定义主题:

 import React from "react";
import ReactDOM from "react-dom";
import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";
import { purple, green } from "@material-ui/core/colors";

const theme = createMuiTheme({
  palette: {
    primary: purple,
    secondary: green
  }
});

function App() {
  return (
    <MuiThemeProvider theme={theme}>
      <Button color="primary">Button1</Button>
      <Button color="secondary">Button2</Button>
    </MuiThemeProvider>
  );
}

ReactDOM.render(<App />, document.getElementById("root"));
 

我收到以下警告: Warning: Material-UI: you are using the deprecated typography variants that will be removed in the next major release.

我没有使用任何印刷术(更不用说任何不推荐使用的印刷术变体)

我为什么收到此警告?有人可以解释一下吗?
在codeandbox上的完整演示: https://codesandbox.io/s/r5v9pjxnq4

最小复制代码: https://codesandbox.io/s/p9628o7wlj
(原来只是使用createMuiTheme也会给出警告!)

解决方案

扩展的错误消息链接到import React from "react"; import ReactDOM from "react-dom"; import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles"; import Button from "@material-ui/core/Button"; import { purple, green } from "@material-ui/core/colors"; const theme = createMuiTheme({ palette: { primary: purple, secondary: green } }); function App() { return ( <MuiThemeProvider theme={theme}> <Button color="primary">Button1</Button> <Button color="secondary">Button2</Button> </MuiThemeProvider> ); } ReactDOM.render(<App />, document.getElementById("root"));

I am getting the following warning: Warning: Material-UI: you are using the deprecated typography variants that will be removed in the next major release.

I am not using any typography (let alone any deprecated typography variant)

Why am I getting this warning? Can someone please explain.
Full demo at codesandbox:
https://codesandbox.io/s/r5v9pjxnq4

Minimal repro code: https://codesandbox.io/s/p9628o7wlj
(Turns out just using createMuiTheme also gives the warning!)

解决方案

The expanded error message links to https://material-ui.com/style/typography/#migration-to-typography-v2 which explains the message in more detail.

Above this you find the deprecated variants which include button. It's not actually deprecated but will be restyled which some consider a breaking change which is why we log this warning.

I agree that it's a bit overzealous to warn just by using createMuiTheme but I suspect that 95% of the use cases touch deprecated variants in some way.

这篇关于在Material-UI中使用自定义主题时不建议使用的字体警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆