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.0.0 to 5.1.0

25

dist/index.js

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

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

@@ -42,6 +42,10 @@ },

const initializedStorageKeys = new Set();
const getUnderlyingValue = (valueOrCallback) => {
const isCallable = (value) => typeof value === 'function';
return isCallable(valueOrCallback) ? valueOrCallback() : valueOrCallback;
};
function useLocalStorageState(key, defaultValue) {
const [state, setState] = react_1.useState(() => {
const isCallable = (value) => typeof value === 'function';
return {
value: storage.get(key, defaultValue),
isPersistent: (() => {

@@ -60,5 +64,2 @@ if (typeof window === 'undefined') {

})(),
value: isCallable(defaultValue)
? storage.get(key, defaultValue())
: storage.get(key, defaultValue),
};

@@ -72,3 +73,3 @@ });

return {
value: value,
value,
isPersistent: storage.set(key, value),

@@ -79,7 +80,5 @@ };

fn.reset = () => {
const isCallable = (value) => typeof value === 'function';
const value = isCallable(defaultValue) ? defaultValue() : defaultValue;
storage.remove(key);
setState({
value: value,
value: getUnderlyingValue(defaultValue),
isPersistent: state.isPersistent,

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

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

@@ -107,4 +106,4 @@ if (initializedStorageKeys.has(key)) {

setState({
isPersistent: true,
value: e.newValue === null ? defaultValue : parseJSON(e.newValue),
value: storage.get(key, defaultValue),
isPersistent: false,
});

@@ -115,3 +114,3 @@ }

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

@@ -118,0 +117,0 @@ }

{
"name": "use-local-storage-state",
"version": "5.0.0",
"version": "5.1.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