0

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?

5
  • V5 now uses 'mode' for the pallet : mode: darkMode ? 'dark' : 'light', Commented Dec 24, 2021 at 10:56
  • @Jamie_D: tried that. Didn't make anything different. Commented Dec 24, 2021 at 10:58
  • Remove the background props and just set the theme to dark ` palette: {mode: 'dark',}` This is built in ... See Dark Mode Commented Dec 24, 2021 at 11:09
  • @Jamie_D: I tried what you wrote. Updated and saved the codesandbox project. The site is still white. Am I missing something more? Commented Dec 24, 2021 at 11:14
  • Updated in answer Commented Dec 24, 2021 at 11:46

2 Answers 2

1

Add CssBaseline to the child

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

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

See CssBaseline

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Too bad this information isn't given in the documentation for ThemeProvider.
As a side note however, the theme provider should be your App.js , providing the theme to all the child components, whereby all you would need to do is call <CssBaseline /> in each child.
1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.