【发布时间】:2017-09-05 18:11:52
【问题描述】:
我有一个场景,我想在我的 JSX 中添加一个简单的布尔值。这只是一个标志,表明某事是否处于活动状态。
<NavItem href="#/gosomewhere" active >
我不确定如何在 JSX 中传递“活动”标志。
我认为这会很好:
const active= location.pathname.match(/^\/gosomewhere/) ? "active" : "";
return(
<NavItem eventKey={1} href="#/gosomewhere" {active} >
Go Somewhere
</NavItem>
)
但是我得到了这个错误:
Module build failed: SyntaxError: Unexpected token, expected ...
在这种情况下我是否需要使用展开运算符?
【问题讨论】:
标签: reactjs jsx react-bootstrap