I wanna switch between two classnames in one element in react by clicking a button. When I click the "Solution" button, the classname of the h1 changes from "solution" to "", but the classname of "blur" stays. My goal is that the classname of "blur" changes to "unblur" when clicking the "Solution" button.
import React from 'react'
import {useState, useEffect} from "react";
import "./Celeb.css"
import images from "../Index.json"
function Celeb() {
const [image, setImage] = useState();
const [name, setName] = useState();
const [unblur, setUnblur] = useState(true);
const [unblurSolution, setUnblurSolution] = useState(true);
const [imageList, setImageList] = useState(images);
...
return (
<div className='celeb'>
<div className='celeb_buttons'>
<button className='play_button' onClick={handleNext}>Next</button>
<button className='play_button' onClick={()=> setUnblur(!unblur)}>Start</button>
<button className='play_button' onClick={()=> setUnblurSolution(!unblurSolution)}>Solution</button>
</div>
<div className='pic'>
<img className={unblur ? "blur" : "unblur"} {...unblurSolution ? "solution" : "unblur"} src={image} />
<h1 className={unblurSolution ? "solution" : ""}>{name}</h1>
</div>
</div>
)
}
Why are u trying to destructor the boolean value here?
Because of this, the value will not read as boolean and use the logic of class name in the quotes