在Material-UI中使用自定义主题时不建议使用的字体警告 [英] Deprecated typography warning when using custom theme in 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
也会给出警告!)
扩展的错误消息链接到 I am getting the following warning:
I am not using any typography (let alone any deprecated typography variant) Why am I getting this warning? Can someone please explain. Minimal repro code: https://codesandbox.io/s/p9628o7wlj 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 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屋!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.
Full demo at codesandbox: https://codesandbox.io/s/r5v9pjxnq4
(Turns out just using createMuiTheme
also gives the warning!)button
. It's not actually deprecated but will be restyled which some consider a breaking change which is why we log this warning.