mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: try/catch for invalid values stored in local storage (#301)
This commit is contained in:
parent
fcb932dc5d
commit
d71cf567e9
@ -1,8 +1,13 @@
|
|||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
|
||||||
const getValueFromLocalStorage = (key: string, defaultValue: any) => {
|
const getValueFromLocalStorage = (key: string, defaultValue: any) => {
|
||||||
const value = window.localStorage.getItem(key);
|
try {
|
||||||
return value ? JSON.parse(value) : defaultValue;
|
const item = window.localStorage.getItem(key);
|
||||||
|
return item ? JSON.parse(item) : defaultValue;
|
||||||
|
} catch (error) {
|
||||||
|
window.localStorage.removeItem(key);
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const useLocalStorage = <T,>(key: string, initialValue: T) => {
|
const useLocalStorage = <T,>(key: string, initialValue: T) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user