Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I change src of 3 image with a button in reactjs?

how can I change src of 3 image with a button in reactjs?

it changes function for dark to light mode.

  const switchTheme = () => {
    const newTheme = theme === "light" ? "dark" : "light";
    setTheme(newTheme);
  };
<button onClick={() => { switchTheme();}} className="buttonMode">

but after that, I should change the src of the image to a white one.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<img id="logo" src={"/LOGO.svg"} alt="" />

LOGO.SVG to LOGOBLACK.svg.

How can I handle that?

>Solution :

You can use ternary operator, just like you did with the newTheme

<img id="logo" src={theme === "light" ? "/Logo.svg" : "/LogoBlack.svg"}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading