2
Reactで基本的な機能を実装しようとする際に問題があります。私は<img>
のリストを持っています。一つをクリックすると、active
クラスをこのimgに追加し、このクラスを他の画像から削除したいと考えています。リスト項目のアクティブなクラスを切り替えるにはどうすればいいですか?
class DefaultImages extends React.Component {
constructor(props) {
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick(e) {
console.log("Element:", e.target)
// I can add the class here, but where to remove from the other images?
}
render() {
var imgSize = "100"
return (
<div>
<img onClick={this.handleClick} src="img/demo.png" width={imgSize} height={imgSize} />
<img onClick={this.handleClick} src="img/demo2.png" width={imgSize} height={imgSize} />
<img onClick={this.handleClick} src="img/demo3.jpg" width={imgSize} height={imgSize} />
<img onClick={this.handleClick} src="img/demo4.png" width={imgSize} height={imgSize} />
</div>
)
}
}
私がクリックした画像からクラスをトグルする方法を知っているが、どのように私は兄弟画像からアクティブなクラスを削除することができますか?