Profile picture of Michael GroßklausMichael Großklaus

RSS
Color scheme

TIL: `storage` event for localStorage updates

There is a storage event that gets fired when the local storage for a site is updated:

// Listen for local storage changes on our theme key. This lets
// one tab to be notified if the theme is changed in another,
// and update itself accordingly.
window.addEventListener("storage", (e) => {
    if (e.key == LOCAL_STORAGE_KEY_THEME) {
        setThemeFromLocalStorageOrMediaPreference()
    }
})