在下面的示例中,我想单击正方形并删除 className .red-square,然后使用 onclick() 添加 className .green-square
import { useState } from "react";
const App = () => {
const [isRed, setIsRed] = useState(true);
const handleClick = () => setIsRed(!isRed);
return <div
onClick={handleClick}
className={isRed ? "red-square" : "green-square"}>
</div>
}