diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-09-12 21:49:46 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-09-12 21:49:46 +0200 |
commit | c584c73a6bf4b804a4c5d6cfdcb50b3ed308e5e3 (patch) | |
tree | 1ccee80c1653d2f83e7ddffb9f012fac32d4e049 /util | |
parent | a21b4afd4f54a53e5d563c3d02195e05f48a4700 (diff) |
feat: #70 label text wrapping
Diffstat (limited to 'util')
-rw-r--r-- | util/persistant-state.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/util/persistant-state.ts b/util/persistant-state.ts index 707c029..2907e70 100644 --- a/util/persistant-state.ts +++ b/util/persistant-state.ts @@ -11,13 +11,15 @@ export function usePersistantState<V>( const storageValue = storage.get() const calculatedDefaultValue = storageValue !== undefined ? storageValue : defaultValue - if (calculatedDefaultValue !== storageValue) { - storage.update(calculatedDefaultValue) - } const calculatedDefaultValueObject = - typeof storageValue === 'object' - ? { ...storageValue, ...calculatedDefaultValue } + storageValue != null && + typeof storageValue === 'object' && + Array.isArray(storageValue) === false + ? { ...defaultValue, ...storageValue } : calculatedDefaultValue + if (calculatedDefaultValueObject !== storageValue) { + storage.update(calculatedDefaultValueObject) + } const [value, setValue] = useState<V>(calculatedDefaultValueObject) // change state gracefully when changing the storageKey |