JSFiddle - React, Tailwind, and code Playground
HTML
<button id="increase">Increase</button><button id="decrease">Decrease</button>
<span id="counter">0</span>
JavaScript
$(increase).click(function(){
var count = +$("#counter").text() + 1;
history.pushState({count:count});
$(counter).text(count);
})
$(decrease).click(function(){
var count = +$("#counter").text() - 1;
history.pushState({count:count});
$(counter).text(count);
})
$(window).on("popstate",function(e){
console.log(e);
if (e.originalEvent.state) {
$(counter).text(e.originalEvent.state.count);
}
else {
// set to default
$(counter).text("0");
}
})