mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-18 20:09:08 +02:00
ff8d983d7e
* refactor: remove unused FeatureToggleListItemChip * refactor: remove unused archive.module.scss * refactor: remove unused ShowArchive route * refactor: port FeatureToggleList to TS/SWR * refactor: fix IUseFeaturesOutput interface prefix * refactor: remove unnecessary pages files * refactor: persist the features sort/filter state * refactor: format files * refactor: fix FeatureToggleListContainer file name * refactor: fix arrow function syntax * refactor: improve storage helper comments
30 lines
867 B
TypeScript
30 lines
867 B
TypeScript
// Get an item from localStorage.
|
|
// Returns undefined if the browser denies access.
|
|
export function getLocalStorageItem<T>(key: string): T | undefined {
|
|
try {
|
|
return parseStoredItem<T>(window.localStorage.getItem(key));
|
|
} catch (err: unknown) {
|
|
console.warn(err);
|
|
}
|
|
}
|
|
|
|
// Store an item in localStorage.
|
|
// Does nothing if the browser denies access.
|
|
export function setLocalStorageItem(key: string, value: unknown) {
|
|
try {
|
|
window.localStorage.setItem(key, JSON.stringify(value));
|
|
} catch (err: unknown) {
|
|
console.warn(err);
|
|
}
|
|
}
|
|
|
|
// Parse an item from localStorage.
|
|
// Returns undefined if the item could not be parsed.
|
|
function parseStoredItem<T>(data: string | null): T | undefined {
|
|
try {
|
|
return data ? JSON.parse(data) : undefined;
|
|
} catch (err: unknown) {
|
|
console.warn(err);
|
|
}
|
|
}
|