use-local-storage-state
Advanced tools
Comparing version 17.1.0 to 17.2.0
@@ -14,5 +14,5 @@ import storage from './storage'; | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
return useClientLocalStorageState(key, defaultValue, (options === null || options === void 0 ? void 0 : options.ssr) === true, (options === null || options === void 0 ? void 0 : options.crossSync) !== false); | ||
return useClientLocalStorageState(key, defaultValue, (options === null || options === void 0 ? void 0 : options.ssr) === true, (options === null || options === void 0 ? void 0 : options.storageSync) !== false); | ||
} | ||
function useClientLocalStorageState(key, defaultValue, ssr, crossSync) { | ||
function useClientLocalStorageState(key, defaultValue, ssr, storageSync) { | ||
const initialDefaultValue = useRef(defaultValue).current; | ||
@@ -43,3 +43,3 @@ // `id` changes every time a change in the `localStorage` occurs | ||
useEffect(() => { | ||
if (!crossSync) { | ||
if (!storageSync) { | ||
return undefined; | ||
@@ -54,3 +54,3 @@ } | ||
return () => window.removeEventListener('storage', onStorage); | ||
}, [key, crossSync]); | ||
}, [key, storageSync]); | ||
// - adds this hook to the `activeHooks` array. see the `activeHooks` declaration above for a | ||
@@ -57,0 +57,0 @@ // more detailed explanation |
{ | ||
"name": "use-local-storage-state", | ||
"version": "17.1.0", | ||
"version": "17.2.0", | ||
"description": "React hook that persist data in localStorage", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -174,3 +174,3 @@ # `use-local-storage-state` | ||
### `options.crossSync` | ||
### `options.storageSync` | ||
@@ -177,0 +177,0 @@ Type: `boolean` |
@@ -5,3 +5,3 @@ import type { Dispatch, SetStateAction } from 'react'; | ||
defaultValue?: T; | ||
crossSync?: boolean; | ||
storageSync?: boolean; | ||
}; | ||
@@ -8,0 +8,0 @@ export declare type LocalStorageState<T> = [ |
@@ -19,6 +19,6 @@ "use strict"; | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
return useClientLocalStorageState(key, defaultValue, (options === null || options === void 0 ? void 0 : options.ssr) === true, (options === null || options === void 0 ? void 0 : options.crossSync) !== false); | ||
return useClientLocalStorageState(key, defaultValue, (options === null || options === void 0 ? void 0 : options.ssr) === true, (options === null || options === void 0 ? void 0 : options.storageSync) !== false); | ||
} | ||
exports.default = useLocalStorageState; | ||
function useClientLocalStorageState(key, defaultValue, ssr, crossSync) { | ||
function useClientLocalStorageState(key, defaultValue, ssr, storageSync) { | ||
const initialDefaultValue = (0, react_1.useRef)(defaultValue).current; | ||
@@ -49,3 +49,3 @@ // `id` changes every time a change in the `localStorage` occurs | ||
(0, react_1.useEffect)(() => { | ||
if (!crossSync) { | ||
if (!storageSync) { | ||
return undefined; | ||
@@ -60,3 +60,3 @@ } | ||
return () => window.removeEventListener('storage', onStorage); | ||
}, [key, crossSync]); | ||
}, [key, storageSync]); | ||
// - adds this hook to the `activeHooks` array. see the `activeHooks` declaration above for a | ||
@@ -63,0 +63,0 @@ // more detailed explanation |
28199