[英]'Active' styling not being applied in conditional statement in React
My file throws an error that says 'active' is not defined when I write this conditional statement for my className:当我为我的类名编写此条件语句时,我的文件抛出了一个错误,提示“未定义活动”:
const NavigationItem = (props) => (
<li className='NavigationItem'>
<a href={props.link}
className={props.active ? active : null}>{props.children}
</a>
</li>)
This is how I'm writing my component and passing active:这就是我编写组件并传递活动的方式:
<NavigationItem link='/' active >Builder</NavigationItem>
I tried importing classes and doing classes.active in the className declaration and while that gets rid of the error the active is not applied.我尝试在 className 声明中导入类并执行 classes.active,虽然这消除了错误,但未应用 active。
const NavigationItem = (props) => (
<li className='NavigationItem'>
<a href={props.link}
className={props.active ? 'active' : null}>{props.children}
</a>
</li>)
you need turn active to string:D你需要激活字符串:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.