所以我有一个这样的 jsx
<img
onClick={(event) => this.handleImgClick(event)}
id="typeLightBox"
className={`${this.state.popupType === 'typeLightBox' ? 'selected' : ''}`}
src="url"
/>
在 className 定义中,我想知道是否有任何方法可以获得此特定 img 的 id 而不是手动编写 id?
最简单的解决方案可能是将它放在一个变量中:
const id = "typeLightBox";
return <img
onClick={(event) => this.handleImgClick(event)}
id={id}
className={`${this.state.popupType === id ? 'selected' : ''}`}
src="url"
/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句