css - 带有 css 模块的 NextJS 条件类给出控制台警告
问题描述
我正在处理 NextJS 项目,我需要在一个元素上有 2 个类,但其中一个是有条件地添加的。我正在使用css模块。
我知道如何添加 2 个类 -className={`${styles.class1} ${styles.class2}`}
这很好用,但是当我想有条件地添加 class2 时,我会在控制台中收到警告:
Warning: Received `false` for a non-boolean attribute `className`.
If you want to write it to the DOM, pass a string instead: className="false" or className={value.toString()}.
If you used to conditionally omit it with className={condition && value}, pass className={condition ? value : undefined} instead.
这是我的代码:
import styles from './styles.module.css'
<div className={`${styles.class1} ${isShowLinks ? styles.class2 : undefined}`}>
Code here
</div>
我也尝试使用 {isShowLinks && styles.class2} 但我在控制台中收到相同的警告。
我做错了什么?
解决方案
推荐阅读
- vbscript - 将本地计算机描述写入 AD
- python - 在python中的指定时间,有没有更简洁的方法来获取今天的日期
- visual-studio-2019 - 如何访问和添加/修改 MainWindowTitleBar 中的控件
- javascript - TinyMCE 内联工具栏插入图像问题
- python - 如何在 Python 中循环多个变量
- oracle - oracle中带有多个查询的游标无法编译
- javascript - 如何在 jQuery-validate 中指定已验证的字段
- java - POJO 到 JSON 的转换不适用于以“is”开头的字符串变量
- arrays - 如何在 Julia 的数组中交换一个特定值?
- python - Cifar100 只有 16 个训练图像和 16 个训练标签