css - 在 React 中添加和删除类
解决方案
const [isRotated, setIsRotated] = useState(false);
handleClick() {
setIsRotated(true)
}
<button className={isRotated && 'rotate-class'} onClick={handleClick} />
{ !isRotated && <Element/>} // this will hide the element when clicked on the button
这将是一种比设置display: none
其他元素更好的方法,但如果您必须这样做,请执行以下操作:
<Element style={{ display: isRotated ? 'none': 'block' }} /> // I'm guessing the default style of display is 'block' of the elements you want to hide
推荐阅读
- javascript - Firebase Firestore endBefore() 处理数据末尾
- bash - 如何使用 sed 或任何其他方法仅替换 magento envfile 中的 dbpassword
- architecture - 构建应用程序的授权在哪里是必要的?
- python - Django - 模型在字符串 'MM/DD/YYYY' 中有日期,在这种情况下我如何 order_by(date)?
- rust - 生成图像的快速 2D 绘图
- javascript - 在按钮单击事件上模拟击键的问题
- html - 如何使用 selenium 在跨度内定位字符串
- math - 公钥是如何从比特币中的私钥推导出来的?
- java - JAVA:哪个对象在多线程中调用 run() 方法
- python - django.db.utils.ProgrammingError:关系“database_class”不存在