Skip to content

Commit

Permalink
Use safeParse util instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro-Vega committed Oct 10, 2024
1 parent c09ba7a commit f45270b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { Logger } from "../utils";
import { Logger, safeParse } from "../utils";

/**
* Custom hook to manage state synchronized with localStorage.
Expand All @@ -14,7 +14,7 @@ export const useLocalStorage = <T>(key: string, initialValue: T): [T, (value: T)
}
try {
const item = window.localStorage.getItem(key);
return item ? (JSON.parse(item) as T) : initialValue;
return safeParse<T>(item, initialValue);
} catch (error) {
Logger.error(error?.toString());
return initialValue;
Expand Down

0 comments on commit f45270b

Please sign in to comment.