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 16.0.0 to 16.0.1

9

es/src/useLocalStorageState.js

@@ -20,3 +20,2 @@ import storage from './storage';

function useClientLocalStorageState(key, options) {
const isFirstRender = useRef(true);
const defaultValue = useRef(options === null || options === void 0 ? void 0 : options.defaultValue).current;

@@ -32,2 +31,5 @@ // `id` changes every time a change in the `localStorage` occurs

unstable_batchedUpdates(() => {
// 🐛 `setValue()` during render doesn't work
// https://github.com/astoilkov/use-local-storage-state/issues/43
forceUpdate();
for (const update of activeHooks) {

@@ -67,7 +69,8 @@ if (update.key === key) {

// - related: https://github.com/astoilkov/use-local-storage-state/issues/43
const isFirstSsrRender = useRef(options === null || options === void 0 ? void 0 : options.ssr).current === true && isFirstRender.current;
const isFirstRenderRef = useRef(true);
const isFirstSsrRender = useRef(options === null || options === void 0 ? void 0 : options.ssr).current === true && isFirstRenderRef.current;
isFirstRenderRef.current = false;
if (isFirstSsrRender &&
(storage.data.has(key) || defaultValue !== storage.get(key, defaultValue))) {
forceUpdate();
isFirstRender.current = false;
}

@@ -74,0 +77,0 @@ // initial issue: https://github.com/astoilkov/use-local-storage-state/issues/26

{
"name": "use-local-storage-state",
"version": "16.0.0",
"version": "16.0.1",
"description": "React hook that persist data in localStorage",

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

@@ -26,3 +26,2 @@ "use strict";

function useClientLocalStorageState(key, options) {
const isFirstRender = (0, react_1.useRef)(true);
const defaultValue = (0, react_1.useRef)(options === null || options === void 0 ? void 0 : options.defaultValue).current;

@@ -38,2 +37,5 @@ // `id` changes every time a change in the `localStorage` occurs

(0, react_dom_1.unstable_batchedUpdates)(() => {
// 🐛 `setValue()` during render doesn't work
// https://github.com/astoilkov/use-local-storage-state/issues/43
forceUpdate();
for (const update of activeHooks) {

@@ -73,7 +75,8 @@ if (update.key === key) {

// - related: https://github.com/astoilkov/use-local-storage-state/issues/43
const isFirstSsrRender = (0, react_1.useRef)(options === null || options === void 0 ? void 0 : options.ssr).current === true && isFirstRender.current;
const isFirstRenderRef = (0, react_1.useRef)(true);
const isFirstSsrRender = (0, react_1.useRef)(options === null || options === void 0 ? void 0 : options.ssr).current === true && isFirstRenderRef.current;
isFirstRenderRef.current = false;
if (isFirstSsrRender &&
(storage_1.default.data.has(key) || defaultValue !== storage_1.default.get(key, defaultValue))) {
forceUpdate();
isFirstRender.current = false;
}

@@ -80,0 +83,0 @@ // initial issue: https://github.com/astoilkov/use-local-storage-state/issues/26

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