I found solution from github, simply wrap the code with <StylesProvider injectFirst>
, because in material-ui v5, the Typography, Button, etc components are migrated to emotion, so we need to use the <StylesProvider injectFirst>
to keep the CSS injection right order between emotion and JSS.
Here is the original answer from @mnajdova
https://github.com/mui-org/material-ui/issues/24109#issuecomment-750794821
The following code should work correctly
import { Button, AppBar, Toolbar, StylesProvider } from "@material-ui/core";
import React from "react";
export default function App() {
return (
<StylesProvider injectFirst>
<div className="App">
<AppBar color="primary" position="static">
<Toolbar>I am AppBar! Where is my color?</Toolbar>
</AppBar>
<Button color="primary" variant="contained">
color
</Button>
</div>
</StylesProvider>
);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…