Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

328
Views
How to switch custom themes in react js

I want to change themes in React.js according to condition being true or false, but when I change inserted styles in app class it only changes innerElements not the entire body.

app.jsx

import "./styles.css";
import { dark, light } from "./comp/themes";

export default function App() {
  const isDarkMode = true;
  const DarkMode = isDarkMode ? dark : light
document.body.style.background={DarkMode};
  return (
    <div className="App">
      <h1>hi</h1>
    </div>
  );
}

./comp/themes.jsx

export const dark = { backgroundColor: "rgb(38, 38, 38)", color: "white" };

export const light = { backgroundColor: "white", color: "black" };

help me to achieve to change the themes. Thanks in advance

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think you are trying to assign the object's background property and not a string. document.body.style.background={DarkMode.backgroundColor}

about 4 years ago · Juan Pablo Isaza Report

0

figured it out

app.js

import "./styles.css";
import { dark, light } from "./comp/themes";
import Toggler from "./comp/Switch";

export default function App() {
  const isDarkMode = false;
  const DarkMode = isDarkMode ? dark : light
  document.body.style.backgroundColor=DarkMode.backgroundColor;
  document.body.style.color=DarkMode.color;

  

  return (
    <div className="App">
      <h1>hi</h1>
    </div>
  );
}
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!