JSFiddle - React, Tailwind, and code Playground
HTML
<button onclick="changeBackground();">
Change
</button>
JavaScript
if(localStorage.bgcolor) {
document.body.style.backgroundColor = localStorage.bgcolor;
}
function changeBackground() {
var currentValue = localStorage.bgcolor || 'white'; // default is white
currentValue = currentValue == 'white' ? 'black' : 'white';
localStorage.setItem('bgcolor', document.body.style.backgroundColor = currentValue);
}