mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-15 00:37:15 +02:00
fix: prefix localStorage key with authority id
Prefixing the localStorage key with the authority id fixes an issue that arises when multiple services are displayed in an iframe on a webpage.
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { authority } from "../socket";
|
||||
|
||||
export default function useLocalStorage(key: string, defaultValue: unknown) {
|
||||
const [value, setValue] = useState(() => {
|
||||
const storedValue = localStorage.getItem(key);
|
||||
const storedValue = localStorage.getItem(`${authority}:${key}`);
|
||||
if (storedValue) {
|
||||
return JSON.parse(storedValue);
|
||||
}
|
||||
@ -11,7 +12,7 @@ export default function useLocalStorage(key: string, defaultValue: unknown) {
|
||||
|
||||
useEffect(() => {
|
||||
if (value === undefined) return;
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
localStorage.setItem(`${authority}:${key}`, JSON.stringify(value));
|
||||
}, [value, key]);
|
||||
|
||||
return [value, setValue];
|
||||
|
Reference in New Issue
Block a user