Skip to content

Commit

Permalink
Handle null and undefined in default useSavedState
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbl committed Sep 2, 2024
1 parent 93c6e7b commit e047172
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/renderer/react/hooks/useSavedState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ function serializeImplicit<T>(value: T): string {
}

function deserializeImplicit<T>(value: string): T {
// TODO: just use JSON.stringify / JSON.parse for all saved state
// but needs a migration path for existing users

// hack around stringified null and undefined values since the string
// versions of these values aren't actually valid for any existing use case
if (value === 'null') {
return null as unknown as T;
}
if (value === 'undefined') {
return undefined as unknown as T;
}

return value as unknown as T;
}

Expand Down

0 comments on commit e047172

Please sign in to comment.