From c584c73a6bf4b804a4c5d6cfdcb50b3ed308e5e3 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Sun, 12 Sep 2021 21:49:46 +0200 Subject: feat: #70 label text wrapping --- util/persistant-state.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'util/persistant-state.ts') 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( 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(calculatedDefaultValueObject) // change state gracefully when changing the storageKey -- cgit v1.2.3