UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

26 lines 829 B
import { useStorageValue, } from './useStorageValue'; import { isBrowser, noop } from '../../util/const'; let IS_LOCAL_STORAGE_AVAILABLE; try { IS_LOCAL_STORAGE_AVAILABLE = isBrowser && Boolean(globalThis.localStorage); } catch (_a) { IS_LOCAL_STORAGE_AVAILABLE = false; } /** * Manages a single localStorage key. */ export const useLocalStorageValue = IS_LOCAL_STORAGE_AVAILABLE ? (key, options) => useStorageValue(localStorage, key, options) : (_key, _options) => { if (isBrowser && process.env.NODE_ENV === 'development') { console.warn('LocalStorage is not available in this environment'); } return { value: undefined, set: noop, remove: noop, fetch: noop, }; }; //# sourceMappingURL=useLocalStorageValue.js.map