Fixed getItem() with a default value
This commit is contained in:
parent
3b9655f6fe
commit
246b406e07
|
@ -4,10 +4,9 @@ export function setItem(k: string, v: string): void {
|
||||||
export function getItem(k: string): string | null
|
export function getItem(k: string): string | null
|
||||||
export function getItem(k: string, defaultValue: any): string
|
export function getItem(k: string, defaultValue: any): string
|
||||||
export function getItem(k: string, defaultValue?: any): string | null {
|
export function getItem(k: string, defaultValue?: any): string | null {
|
||||||
try {
|
const val = localStorage.getItem(k)
|
||||||
return localStorage.getItem(k) ?? null
|
if (defaultValue !== undefined && val === null) {
|
||||||
}
|
return defaultValue
|
||||||
catch (e) {
|
|
||||||
return defaultValue ?? null
|
|
||||||
}
|
}
|
||||||
|
return val
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user