-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Could this library provide a "sharedSessionStorage" that would work just like "sessionStorage", but with synchronization between different tabs?
It could use BroadcastChannel to keep them in sync.
I think it should look like this:
const bc = new BroadcastChannel('sharedSessionStorage');
bc.onmessage = (evt) => {
const { action, key, value } = JSON.parse(evt.data);
switch (action) {
case 'setItem':
sessionStorage.setItem(key, value);
break;
case 'removeItem':
sessionStorage.removeItem(key);
break;
default:
}
};
export const sharedSessionStorage = {
getItem: (key) => sessionStorage.getItem(key),
setItem: (key, value) => {
sessionStorage.setItem(key, value);
bc.postMessage(JSON.stringify({ action: 'setItem', key, value }));
},
removeItem: (key) => {
sessionStorage.removeItem(key);
}
};But it doesn't seem to notify the useStorageState hooks when a new value is set from a BroadcastChannel message.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working