mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-09 15:00:40 +02:00
Merge pull request #236 from tiqi-group/fix/local_storage_usage
fix: prefix localStorage key with authority id
This commit is contained in:
commit
28a1cc7cd3
@ -1,8 +1,9 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
import { authority } from "../socket";
|
||||||
|
|
||||||
export default function useLocalStorage(key: string, defaultValue: unknown) {
|
export default function useLocalStorage(key: string, defaultValue: unknown) {
|
||||||
const [value, setValue] = useState(() => {
|
const [value, setValue] = useState(() => {
|
||||||
const storedValue = localStorage.getItem(key);
|
const storedValue = localStorage.getItem(`${authority}:${key}`);
|
||||||
if (storedValue) {
|
if (storedValue) {
|
||||||
return JSON.parse(storedValue);
|
return JSON.parse(storedValue);
|
||||||
}
|
}
|
||||||
@ -11,7 +12,7 @@ export default function useLocalStorage(key: string, defaultValue: unknown) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (value === undefined) return;
|
if (value === undefined) return;
|
||||||
localStorage.setItem(key, JSON.stringify(value));
|
localStorage.setItem(`${authority}:${key}`, JSON.stringify(value));
|
||||||
}, [value, key]);
|
}, [value, key]);
|
||||||
|
|
||||||
return [value, setValue];
|
return [value, setValue];
|
||||||
|
File diff suppressed because one or more lines are too long
@ -7,7 +7,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="theme-color" content="#000000" />
|
<meta name="theme-color" content="#000000" />
|
||||||
<meta name="description" content="Web site displaying a pydase UI." />
|
<meta name="description" content="Web site displaying a pydase UI." />
|
||||||
<script type="module" crossorigin src="/assets/index-BLJetjaQ.js"></script>
|
<script type="module" crossorigin src="/assets/index-DK2ZYE8p.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-DJzFvk4W.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-DJzFvk4W.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user