This is perhaps a simple Material UI Theme Customization question.
What I want to do is to override the default styling on <body> (and other common tags in the future). Right now at the root of my React tree: 
import theme from './mui-theme'
ReactDOM.render(
  <Router>
    <ThemeProvider theme={theme}>
      <StylesProvider injectFirst>
        {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
        <CssBaseline />
        <App />
      </StylesProvider>
    </ThemeProvider>
  </Router>,
  document.getElementById('root'),
);
There's a theme that specifies some things but leaves out 'body1' 
const theme = useTheme() and console.log(theme) shows that it is defined as:
typography:
  body1:
    fontFamily: "Roboto,"Helvetica Neue""
    fontSize: "1rem"
    fontWeight: 400
    lineHeight: 1.5
This is the setting I want. However to use that setting I have to use the Typography tag with variant='body1'. Otherwise, text inside a div has styling provided by CssBaseline. That's the rule on the body tag: font-size: .875rem; which I wish to override.
Do people override styling provided by CssBaseline by using createMuiTheme? If so, I added:
body: {
    fontSize: '1rem',
  },
Which shows up on console.log(theme), but how tell the <body> tag to actually use that style?
Here is an example of overriding this aspect of CssBaseline:
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
const styles = theme => ({
  "@global": {
    body: {
      ...theme.typography.body1
    }
  }
});
function MyCssBaseline() {
  return null;
}
MyCssBaseline.propTypes = {
  classes: PropTypes.object.isRequired
};
export default withStyles(styles)(MyCssBaseline);
import React from "react";
import ReactDOM from "react-dom";
import CssBaseline from "@material-ui/core/CssBaseline";
import MyCssBaseline from "./MyCssBaseline";
function App() {
  return (
    <>
      <CssBaseline />
      <MyCssBaseline />
      <span>
        Here is some text in the body that is getting the body1 styling due to
        MyCssBaseline.
      </span>
    </>
  );
}
ReactDOM.render(<App />, document.querySelector("#root"));
Reference: https://material-ui.com/styles/advanced/#global-css
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With