cpns / apps /web /src /hooks /use-local-storage-boolean.ts
rogasper's picture
feat: refactor Sidebar component to use grouped navigation items and enhance mobile navigation. Introduce AdvancedFilters, BundleSidebar, FilterBar, and other components for improved question and section management. Implement SoalBrowser and SectionBrowser for better content display, and add hooks for local storage management. Update bank route to integrate new components and enhance filtering capabilities.
32e08ac
Raw
History Blame Contribute Delete
539 Bytes
import { useState, useEffect } from "react";
export function useLocalStorageBoolean(key: string, defaultValue: boolean) {
const [value, setValue] = useState(() => {
if (typeof window === "undefined") return defaultValue;
try {
return localStorage.getItem(key) === "true" ? true : defaultValue;
} catch {
return defaultValue;
}
});
useEffect(() => {
try {
localStorage.setItem(key, String(value));
} catch {
// ignore
}
}, [key, value]);
return [value, setValue] as const;
}