これは私のコードです。アドバイスをして、onclick関数の後にアイコンの色を変更したいと思います。jcleryを使ってonclick関数の後にicon色を塗りつぶす方法
<div class="timeline-footer">
<a
id="changeicon"
onClick={(event) => this.handleCount(post.id, event)}
class="m-r-25"
><i class="fa fa-heart-o"></i> {post.rating} Like</a>
</div>
これは私の評価カウント機能である
handleCount(id, event) {
event.classList.toggle("icon-heart");
fetch(this.state.url + '/rating/' + id, {
method: 'POST',
header: {
'Accept': 'applicatoin/json',
'Content-Type': 'application/json'
}
})
.then((response) => {
window.location.reload();
})
}
これに合っている場合むしろ簡単です。クラスをstateプロパティにして、onClick関数の最後に状態を変更することができます。 – Gegenwind
btw、反応では、 'class'の代わりに' className'を使います。[ReactJSのDOM要素](https://reactjs.org/docs/dom-elements.html) – 3Dos