aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-01 11:36:15 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-01 11:36:15 -0700
commit90f292b7739835202842d88eeaf55a531d29d3c3 (patch)
treefd55ee9bb5b67cfe03d5873aea86d5697367f121 /modern/src/common
parentf2bd440c7fdf8857a5704f214d96aba3345a14e7 (diff)
downloadtrackermap-web-90f292b7739835202842d88eeaf55a531d29d3c3.tar.gz
trackermap-web-90f292b7739835202842d88eeaf55a531d29d3c3.tar.bz2
trackermap-web-90f292b7739835202842d88eeaf55a531d29d3c3.zip
Persist map layer
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/usePersistedState.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/modern/src/common/usePersistedState.js b/modern/src/common/usePersistedState.js
index 0a7a990e..8bc4401f 100644
--- a/modern/src/common/usePersistedState.js
+++ b/modern/src/common/usePersistedState.js
@@ -1,5 +1,9 @@
import { useEffect, useState } from 'react';
+export const savePersistedState = (key, value) => {
+ window.localStorage.setItem(key, JSON.stringify(value));
+};
+
export default (key, defaultValue) => {
const [value, setValue] = useState(() => {
const stickyValue = window.localStorage.getItem(key);
@@ -7,7 +11,7 @@ export default (key, defaultValue) => {
});
useEffect(() => {
- window.localStorage.setItem(key, JSON.stringify(value));
+ savePersistedState(key, value);
}, [key, value]);
return [value, setValue];