I am trying to create a reactions button to post / retrieve data from the server. I have did the post and retrieve, but the issue is that whenever I post, if I check developer tools, it says PENDING for the api call. If i refresh the page, I get the new data.
Here is my post:
getId = async(reaction) => {
let eSlug = this.state.slug;
let data = {
reactiond: reaction,
eSlugd: eSlug
}
await fetch("http://localhost:9000/react/",
{
method: "post",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => response.json())
.then(data => {
console.log(data)
});
}
My reaction render:
<div className="row">
<div className="col-all">
<button className="emoji-static">
<span className="emoji-like">Like</span>
<span className="emoji-container">
<span className="emoji cool zoom" onClick={this.getId.bind(null,"1")}>
<img className="svg" src="/img/svg/cool.svg" alt="Cool" />
<span className="counter">{this.state.coolReaction}</span>
</span>
<span className="emoji love zoom" onClick={this.getId.bind(null,"2")}>
<img className="svg" src="/img/svg/love.svg" alt="Love" />
<span className="counter">{this.state.loveReaction}</span>
</span>
<span className="emoji laugh zoom" onClick={this.getId.bind(null,"3")}>
<img className="svg" src="/img/svg/laugh.svg" alt="Laugh" />
<span className="counter">{this.state.laughReaction}</span>
</span>
<span className="emoji sad zoom" onClick={this.getId.bind(null,"4")}>
<img className="svg" src="/img/svg/sad.svg" alt="Sad" />
<span className="counter">{this.state.sadReaction}</span>
</span>
<span className="emoji zoom" onClick={this.getId.bind(null,"5")}>
<img className="svg" src="/img/svg/angry.svg" alt="Angry" />
<span className="counter">{this.state.angryReaction}</span>
</span>
</span>
</button>
</div>
</div>
I do not understand why is it stuck in pending and because of this, I do not get anything for console.log Can you point me in the right direction? I am a complete beginner in React, coming from PHP.