• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

116
Views
Custom Theme not applying to components

Hello I am trying to apply my custom theme (simple color change) from Theme.js to the components in App.js. However, the components are still using the default theme colors. After some time, I haven't been able to change the primary and secondary colors.

Theme.js

import React from "react";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { orange } from "@mui/material/colors";

const theme = {
  palette: {
    primary: {
      main: orange[500],
    },
     secondary: orange[900],
  },
};

function Theme() {
  return theme;
}

export default Theme;

App.js

//import logo from "./logo.svg";
//import './App.css';
import LandingPage from "../LandingPage";
import About from "../About";
import React from "react";
import { ThemeProvider } from "@mui/styles";
import { createTheme } from "@mui/material/styles";
import Box from "@mui/material/Box";
import { Routes, Route } from "react-router-dom";
import Navbar from "../Navbar";
import CourseHome from "../CourseHome";
import Theme from "../Theme";

const theme = createTheme(Theme);

function App() {
  return (
    <ThemeProvider theme={theme}>
      <Box
        sx={{
          width: "100%",
          height: "100%",
        }}
      >
        <Navbar />

        <Box
          sx={{
            height: "calc(100% - 4rem)",
            width: "100%",
          }}
        >
          <Routes>
            <Route exact path="/" element={<LandingPage />}></Route>
            <Route path="/about" element={<About />}></Route>
            <Route path="/home" element={<LandingPage />}></Route>
            <Route path="/course-home" element={<CourseHome />}></Route>
          </Routes>
        </Box>
      </Box>
    </ThemeProvider>
  );
}

export default App;

Example of use in Navbar:

<AppBar position="static" color="secondary">

I can't figure out why the components are still using the default theme colors.

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

use this instead of what you have in theme.js

const theme = createTheme({
  palette: {
    primary: {
      main: orange[500],
    },
     secondary: orange[900],
  },
});
almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error