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.
<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"}