aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-09-02 23:00:37 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-09-02 23:00:37 -0700
commit26f4e5835d5fb2f0b5035837e2e90ef012b242f0 (patch)
treed923e21567684dea67c7c89557fefcf684b292d8 /modern/src/common
parent10cc10e0e88569cc48d86e9ab4d90538683bfaf6 (diff)
downloadetbsa-traccar-web-26f4e5835d5fb2f0b5035837e2e90ef012b242f0.tar.gz
etbsa-traccar-web-26f4e5835d5fb2f0b5035837e2e90ef012b242f0.tar.bz2
etbsa-traccar-web-26f4e5835d5fb2f0b5035837e2e90ef012b242f0.zip
Reimplement localization provider
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/usePersistedState.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/modern/src/common/usePersistedState.js b/modern/src/common/usePersistedState.js
new file mode 100644
index 0000000..0a6627c
--- /dev/null
+++ b/modern/src/common/usePersistedState.js
@@ -0,0 +1,15 @@
+import { useState } from 'react';
+
+export default usePersistedState = (key, defaultValue) => {
+
+ const [value, setValue] = useState(() => {
+ const stickyValue = window.localStorage.getItem(key);
+ return stickyValue ? JSON.parse(stickyValue) : defaultValue;
+ });
+
+ React.useEffect(() => {
+ window.localStorage.setItem(key, JSON.stringify(value));
+ }, [key, value]);
+
+ return [value, setValue];
+};