问题
In the following code code, I am using a custom theme in 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"));
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!)
回答1:
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.
回答2:
I just add in my index.html
:
<script>window.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true</script>
回答3:
For anyone here this has been addressed in release v3.6.1
来源:https://stackoverflow.com/questions/52904630/deprecated-typography-warning-when-using-custom-theme-in-material-ui