From 90f292b7739835202842d88eeaf55a531d29d3c3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 1 May 2022 11:36:15 -0700 Subject: Persist map layer --- modern/src/common/usePersistedState.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'modern/src/common') 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]; -- cgit v1.2.3