use-local-storage-state
Advanced tools
Comparing version 19.3.0 to 19.3.1
{ | ||
"name": "use-local-storage-state", | ||
"version": "19.3.0", | ||
"version": "19.3.1", | ||
"description": "React hook that persist data in localStorage", | ||
"license": "MIT", | ||
"repository": "astoilkov/use-local-storage-state", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/astoilkov/use-local-storage-state.git" | ||
}, | ||
"funding": "https://github.com/sponsors/astoilkov", | ||
@@ -8,0 +11,0 @@ "homepage": "https://github.com/astoilkov/use-local-storage-state", |
@@ -25,4 +25,5 @@ # `use-local-storage-state` | ||
- Production ready. | ||
- 689 B (brotlied). | ||
- SSR support. | ||
- Works with React 18 concurrent rendering and React 19. | ||
- SSR support. | ||
- Handles the `Window` [`storage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event) event and updates changes across browser tabs, windows, and iframe's. Disable with `storageSync: false`. | ||
@@ -29,0 +30,0 @@ - In-memory fallback when `localStorage` throws an error and can't store the data. Provides a `isPersistent` API to let you notify the user their data isn't currently being stored. |
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'; | ||
// in memory fallback used then `localStorage` throws an error | ||
// in memory fallback used when `localStorage` throws an error | ||
export const inMemoryData = new Map(); | ||
@@ -7,5 +7,5 @@ export default function useLocalStorageState(key, options) { | ||
const [defaultValue] = useState(options === null || options === void 0 ? void 0 : options.defaultValue); | ||
return useBrowserLocalStorageState(key, defaultValue, options === null || options === void 0 ? void 0 : options.storageSync, serializer === null || serializer === void 0 ? void 0 : serializer.parse, serializer === null || serializer === void 0 ? void 0 : serializer.stringify); | ||
return useLocalStorage(key, defaultValue, options === null || options === void 0 ? void 0 : options.storageSync, serializer === null || serializer === void 0 ? void 0 : serializer.parse, serializer === null || serializer === void 0 ? void 0 : serializer.stringify); | ||
} | ||
function useBrowserLocalStorageState(key, defaultValue, storageSync = true, parse = parseJSON, stringify = JSON.stringify) { | ||
function useLocalStorage(key, defaultValue, storageSync = true, parse = parseJSON, stringify = JSON.stringify) { | ||
// we keep the `parsed` value in a ref because `useSyncExternalStore` requires a cached version | ||
@@ -12,0 +12,0 @@ const storageItem = useRef({ |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
17499
110855
189
0