'Unable to set theme in latest MUI v5 with ReactJS

I am building a small, simple Wiki for myself; just started learning React, although I've been working with JavaScript before.

I cannot seem to set the theme. I am trying to set the background to black. I am doing this:

  const darkMode = true;

  const theme = createTheme({
    palette: {
      type: darkMode ? 'dark' : 'light',
      background: {
        default: "#000000",
        paper: "#000000"
      }
    },
  })

And then rendering with:

<ThemeProvider theme={theme}>
...
</ThemeProvider>

codesandbox project

github repo, although it's still very young.

Any idea what I am doing wrong?



Solution 1:[1]

Add CssBaseline to the child

import CssBaseline from '@mui/material/CssBaseline';

<ThemeProvider theme={theme}>
  <CssBaseline />
...
</ThemeProvider>

See CssBaseline

Solution 2:[2]

your import is wrong, you need to import ThemeProvider from /material and not material/styles, like this:

import { ThemeProvider } from "@mui/material";

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jamie_D
Solution 2 Belkacem Yahiaoui