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 5.1.0 to 6.0.0

15

dist/index.js

@@ -18,3 +18,3 @@ "use strict";

catch (_b) {
return getUnderlyingValue(defaultValue);
return unwrapValue(defaultValue);
}

@@ -42,3 +42,3 @@ },

const initializedStorageKeys = new Set();
const getUnderlyingValue = (valueOrCallback) => {
const unwrapValue = (valueOrCallback) => {
const isCallable = (value) => typeof value === 'function';

@@ -48,5 +48,6 @@ return isCallable(valueOrCallback) ? valueOrCallback() : valueOrCallback;

function useLocalStorageState(key, defaultValue) {
const defaultValueRef = react_1.useRef(defaultValue);
const [state, setState] = react_1.useState(() => {
return {
value: storage.get(key, defaultValue),
value: storage.get(key, defaultValueRef.current),
isPersistent: (() => {

@@ -81,3 +82,3 @@ if (typeof window === 'undefined') {

setState({
value: getUnderlyingValue(defaultValue),
value: unwrapValue(defaultValueRef.current),
isPersistent: state.isPersistent,

@@ -87,3 +88,3 @@ });

return fn;
}, [key, defaultValue]);
}, [key]);
react_1.useEffect(() => {

@@ -105,3 +106,3 @@ if (initializedStorageKeys.has(key)) {

setState({
value: storage.get(key, defaultValue),
value: storage.get(key, defaultValueRef.current),
isPersistent: false,

@@ -113,3 +114,3 @@ });

return () => window.removeEventListener('storage', onStorage);
}, [defaultValue]);
}, []);
return [state.value, updateValue, state.isPersistent];

@@ -116,0 +117,0 @@ }

{
"name": "use-local-storage-state",
"version": "5.1.0",
"version": "6.0.0",
"description": "React hook that persist data in local storage. Done right.",

@@ -5,0 +5,0 @@ "license": "MIT",

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