JSFiddle - React, Tailwind, and code Playground
JavaScript
var storageEvent = document.createEvent('Event');
storageEvent.initEvent('onstoragechanged', true, true);
document.addEventListener('onstoragechanged', function (e) {
alert('value added to localstorage');
//or
alert(localStorage.getItem('test'));
}, false);
var oldSetItem = Storage.prototype.setItem;
Storage.prototype.setItem = function() {
oldSetItem.apply(this, arguments);
document.dispatchEvent(storageEvent);
}
localStorage.setItem('test', 'value');