Skip to content

Commit

Permalink
fix: initialize in the useBoolStateCache
Browse files Browse the repository at this point in the history
  • Loading branch information
mnsinri committed Sep 2, 2023
1 parent 27b6268 commit 3efe0d0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hooks/useBoolStateCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { useEffect, useState } from "react";

export const useBoolStateCache = (key: string, initState: boolean) => {
const [value, setter] = useState<boolean>(
localStorage.getItem(key)?.toLocaleLowerCase() === "true" ?? initState
(() => {
const item = localStorage.getItem(key);
return item == null ? initState : item.toLocaleLowerCase() === "true";
})()
);

useEffect(() => {
Expand Down

0 comments on commit 3efe0d0

Please sign in to comment.