I created an IG like button where the number of like changes after a click. I added 2 fetch functions - one with PUT. I tried multiple ways but the results are same - the GET fetch is getting executed first. How can I prevent that?
function liking(tweetid) {
let l = document.querySelector('#numlikes-' + tweetid);
fetch(`tweets/${tweetid}`, {
method: 'PUT',
body: JSON.stringify({
tweet_like: 1
})
});
fetch(`tweets/${tweetid}`)
.then(response => response.json())
.then(post => {
l.innerHTML = post.likes;
});
}