New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

use-local-storage-state

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-local-storage-state - npm Package Compare versions

Comparing version 19.3.0 to 19.3.1

7

package.json
{
"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({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc