@mantine/hooks 4.1.0 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/use-local-storage/use-local-storage.js +8 -1
- package/cjs/use-local-storage/use-local-storage.js.map +1 -1
- package/esm/use-local-storage/use-local-storage.js +8 -1
- package/esm/use-local-storage/use-local-storage.js.map +1 -1
- package/lib/use-local-storage/use-local-storage.d.ts +7 -1
- package/lib/use-local-storage/use-local-storage.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -22,11 +22,12 @@ function deserializeJSON(value) {
|
|
|
22
22
|
function useLocalStorage({
|
|
23
23
|
key,
|
|
24
24
|
defaultValue = void 0,
|
|
25
|
+
getInitialValueInEffect = false,
|
|
25
26
|
deserialize = deserializeJSON,
|
|
26
27
|
serialize = serializeJSON
|
|
27
28
|
}) {
|
|
28
29
|
var _a;
|
|
29
|
-
const [value, setValue] = react.useState(typeof window !== "undefined" && "localStorage" in window ? deserialize((_a = window.localStorage.getItem(key)) != null ? _a : void 0) : defaultValue != null ? defaultValue : "");
|
|
30
|
+
const [value, setValue] = react.useState(typeof window !== "undefined" && "localStorage" in window && !getInitialValueInEffect ? deserialize((_a = window.localStorage.getItem(key)) != null ? _a : void 0) : defaultValue != null ? defaultValue : "");
|
|
30
31
|
const setLocalStorageValue = react.useCallback((val) => {
|
|
31
32
|
if (val instanceof Function) {
|
|
32
33
|
setValue((current) => {
|
|
@@ -50,6 +51,12 @@ function useLocalStorage({
|
|
|
50
51
|
setLocalStorageValue(defaultValue);
|
|
51
52
|
}
|
|
52
53
|
}, [defaultValue, value, setLocalStorageValue]);
|
|
54
|
+
react.useEffect(() => {
|
|
55
|
+
var _a2;
|
|
56
|
+
if (getInitialValueInEffect) {
|
|
57
|
+
setValue(deserialize((_a2 = window.localStorage.getItem(key)) != null ? _a2 : void 0) || (defaultValue != null ? defaultValue : ""));
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
53
60
|
return [value === void 0 ? defaultValue : value, setLocalStorageValue];
|
|
54
61
|
}
|
|
55
62
|
const useLocalStorageValue = useLocalStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-local-storage.js","sources":["../../src/use-local-storage/use-local-storage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface UseLocalStorage<T> {\n key: string;\n defaultValue?: T;\n serialize?(value: T): string;\n deserialize?(value: string): T;\n}\n\nfunction serializeJSON<T>(value: T) {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error('@mantine/hooks use-local-storage: Failed to serialize the value');\n }\n}\n\nfunction deserializeJSON(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nexport function useLocalStorage<T = string>({\n key,\n defaultValue = undefined,\n deserialize = deserializeJSON,\n serialize = serializeJSON,\n}: UseLocalStorage<T>) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? deserialize(window.localStorage.getItem(key) ?? undefined)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (val instanceof Function) {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, serialize(result));\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(deserialize(event.newValue ?? undefined));\n }\n });\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value === undefined ? defaultValue : value, setLocalStorageValue] as const;\n}\n\nexport const useLocalStorageValue = useLocalStorage;\n"],"names":["useState","useCallback","useWindowEvent","useEffect"],"mappings":";;;;;;;AAEA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACvF,GAAG;AACH,CAAC;AACD,SAAS,eAAe,CAAC,KAAK,EAAE;AAChC,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,CAAC;AACM,SAAS,eAAe,CAAC;AAChC,EAAE,GAAG;AACL,EAAE,YAAY,GAAG,KAAK,CAAC;AACvB,EAAE,WAAW,GAAG,eAAe;AAC/B,EAAE,SAAS,GAAG,aAAa;AAC3B,CAAC,EAAE;AACH,EAAE,IAAI,EAAE,CAAC;AACT,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,cAAc,IAAI,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,YAAY,IAAI,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-local-storage.js","sources":["../../src/use-local-storage/use-local-storage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface UseLocalStorage<T> {\n /** Local storage key */\n key: string;\n\n /** Default value that will be set if value is not found in local storage */\n defaultValue?: T;\n\n /** If set to true, value will be update is useEffect after mount */\n getInitialValueInEffect?: boolean;\n\n /** Function to serialize value into string to be save in local storage */\n serialize?(value: T): string;\n\n /** Function to deserialize string value from local storage to value */\n deserialize?(value: string): T;\n}\n\nfunction serializeJSON<T>(value: T) {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error('@mantine/hooks use-local-storage: Failed to serialize the value');\n }\n}\n\nfunction deserializeJSON(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nexport function useLocalStorage<T = string>({\n key,\n defaultValue = undefined,\n getInitialValueInEffect = false,\n deserialize = deserializeJSON,\n serialize = serializeJSON,\n}: UseLocalStorage<T>) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window && !getInitialValueInEffect\n ? deserialize(window.localStorage.getItem(key) ?? undefined)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (val instanceof Function) {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, serialize(result));\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(deserialize(event.newValue ?? undefined));\n }\n });\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n useEffect(() => {\n if (getInitialValueInEffect) {\n setValue(\n deserialize(window.localStorage.getItem(key) ?? undefined) || ((defaultValue ?? '') as T)\n );\n }\n }, []);\n\n return [value === undefined ? defaultValue : value, setLocalStorageValue] as const;\n}\n\nexport const useLocalStorageValue = useLocalStorage;\n"],"names":["useState","useCallback","useWindowEvent","useEffect"],"mappings":";;;;;;;AAEA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACvF,GAAG;AACH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deserializeJSON(value) {
|
|
|
18
18
|
function useLocalStorage({
|
|
19
19
|
key,
|
|
20
20
|
defaultValue = void 0,
|
|
21
|
+
getInitialValueInEffect = false,
|
|
21
22
|
deserialize = deserializeJSON,
|
|
22
23
|
serialize = serializeJSON
|
|
23
24
|
}) {
|
|
24
25
|
var _a;
|
|
25
|
-
const [value, setValue] = useState(typeof window !== "undefined" && "localStorage" in window ? deserialize((_a = window.localStorage.getItem(key)) != null ? _a : void 0) : defaultValue != null ? defaultValue : "");
|
|
26
|
+
const [value, setValue] = useState(typeof window !== "undefined" && "localStorage" in window && !getInitialValueInEffect ? deserialize((_a = window.localStorage.getItem(key)) != null ? _a : void 0) : defaultValue != null ? defaultValue : "");
|
|
26
27
|
const setLocalStorageValue = useCallback((val) => {
|
|
27
28
|
if (val instanceof Function) {
|
|
28
29
|
setValue((current) => {
|
|
@@ -46,6 +47,12 @@ function useLocalStorage({
|
|
|
46
47
|
setLocalStorageValue(defaultValue);
|
|
47
48
|
}
|
|
48
49
|
}, [defaultValue, value, setLocalStorageValue]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
var _a2;
|
|
52
|
+
if (getInitialValueInEffect) {
|
|
53
|
+
setValue(deserialize((_a2 = window.localStorage.getItem(key)) != null ? _a2 : void 0) || (defaultValue != null ? defaultValue : ""));
|
|
54
|
+
}
|
|
55
|
+
}, []);
|
|
49
56
|
return [value === void 0 ? defaultValue : value, setLocalStorageValue];
|
|
50
57
|
}
|
|
51
58
|
const useLocalStorageValue = useLocalStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-local-storage.js","sources":["../../src/use-local-storage/use-local-storage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface UseLocalStorage<T> {\n key: string;\n defaultValue?: T;\n serialize?(value: T): string;\n deserialize?(value: string): T;\n}\n\nfunction serializeJSON<T>(value: T) {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error('@mantine/hooks use-local-storage: Failed to serialize the value');\n }\n}\n\nfunction deserializeJSON(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nexport function useLocalStorage<T = string>({\n key,\n defaultValue = undefined,\n deserialize = deserializeJSON,\n serialize = serializeJSON,\n}: UseLocalStorage<T>) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? deserialize(window.localStorage.getItem(key) ?? undefined)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (val instanceof Function) {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, serialize(result));\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(deserialize(event.newValue ?? undefined));\n }\n });\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value === undefined ? defaultValue : value, setLocalStorageValue] as const;\n}\n\nexport const useLocalStorageValue = useLocalStorage;\n"],"names":[],"mappings":";;;AAEA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACvF,GAAG;AACH,CAAC;AACD,SAAS,eAAe,CAAC,KAAK,EAAE;AAChC,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,CAAC;AACM,SAAS,eAAe,CAAC;AAChC,EAAE,GAAG;AACL,EAAE,YAAY,GAAG,KAAK,CAAC;AACvB,EAAE,WAAW,GAAG,eAAe;AAC/B,EAAE,SAAS,GAAG,aAAa;AAC3B,CAAC,EAAE;AACH,EAAE,IAAI,EAAE,CAAC;AACT,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,cAAc,IAAI,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,YAAY,IAAI,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-local-storage.js","sources":["../../src/use-local-storage/use-local-storage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface UseLocalStorage<T> {\n /** Local storage key */\n key: string;\n\n /** Default value that will be set if value is not found in local storage */\n defaultValue?: T;\n\n /** If set to true, value will be update is useEffect after mount */\n getInitialValueInEffect?: boolean;\n\n /** Function to serialize value into string to be save in local storage */\n serialize?(value: T): string;\n\n /** Function to deserialize string value from local storage to value */\n deserialize?(value: string): T;\n}\n\nfunction serializeJSON<T>(value: T) {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error('@mantine/hooks use-local-storage: Failed to serialize the value');\n }\n}\n\nfunction deserializeJSON(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nexport function useLocalStorage<T = string>({\n key,\n defaultValue = undefined,\n getInitialValueInEffect = false,\n deserialize = deserializeJSON,\n serialize = serializeJSON,\n}: UseLocalStorage<T>) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window && !getInitialValueInEffect\n ? deserialize(window.localStorage.getItem(key) ?? undefined)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (val instanceof Function) {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, serialize(result));\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(deserialize(event.newValue ?? undefined));\n }\n });\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n useEffect(() => {\n if (getInitialValueInEffect) {\n setValue(\n deserialize(window.localStorage.getItem(key) ?? undefined) || ((defaultValue ?? '') as T)\n );\n }\n }, []);\n\n return [value === undefined ? defaultValue : value, setLocalStorageValue] as const;\n}\n\nexport const useLocalStorageValue = useLocalStorage;\n"],"names":[],"mappings":";;;AAEA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACvF,GAAG;AACH,CAAC;AACD,SAAS,eAAe,CAAC,KAAK,EAAE;AAChC,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,CAAC;AACM,SAAS,eAAe,CAAC;AAChC,EAAE,GAAG;AACL,EAAE,YAAY,GAAG,KAAK,CAAC;AACvB,EAAE,uBAAuB,GAAG,KAAK;AACjC,EAAE,WAAW,GAAG,eAAe;AAC/B,EAAE,SAAS,GAAG,aAAa;AAC3B,CAAC,EAAE;AACH,EAAE,IAAI,EAAE,CAAC;AACT,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KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,YAAY,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,KAAK,CAAC,EAAE;AACrD,MAAM,oBAAoB,CAAC,YAAY,CAAC,CAAC;AACzC,KAAK;AACL,GAAG,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;AAClD,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,GAAG,CAAC;AACZ,IAAI,IAAI,uBAAuB,EAAE;AACjC,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,KAAK,YAAY,IAAI,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AAC3I,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK,CAAC,GAAG,YAAY,GAAG,KAAK,EAAE,oBAAoB,CAAC,CAAC;AACzE,CAAC;AACW,MAAC,oBAAoB,GAAG;;;;"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
interface UseLocalStorage<T> {
|
|
2
|
+
/** Local storage key */
|
|
2
3
|
key: string;
|
|
4
|
+
/** Default value that will be set if value is not found in local storage */
|
|
3
5
|
defaultValue?: T;
|
|
6
|
+
/** If set to true, value will be update is useEffect after mount */
|
|
7
|
+
getInitialValueInEffect?: boolean;
|
|
8
|
+
/** Function to serialize value into string to be save in local storage */
|
|
4
9
|
serialize?(value: T): string;
|
|
10
|
+
/** Function to deserialize string value from local storage to value */
|
|
5
11
|
deserialize?(value: string): T;
|
|
6
12
|
}
|
|
7
|
-
export declare function useLocalStorage<T = string>({ key, defaultValue, deserialize, serialize, }: UseLocalStorage<T>): readonly [T, (val: T | ((prevState: T) => T)) => void];
|
|
13
|
+
export declare function useLocalStorage<T = string>({ key, defaultValue, getInitialValueInEffect, deserialize, serialize, }: UseLocalStorage<T>): readonly [T, (val: T | ((prevState: T) => T)) => void];
|
|
8
14
|
export declare const useLocalStorageValue: typeof useLocalStorage;
|
|
9
15
|
export {};
|
|
10
16
|
//# sourceMappingURL=use-local-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-local-storage.d.ts","sourceRoot":"","sources":["../../src/use-local-storage/use-local-storage.ts"],"names":[],"mappings":"AAGA,UAAU,eAAe,CAAC,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"use-local-storage.d.ts","sourceRoot":"","sources":["../../src/use-local-storage/use-local-storage.ts"],"names":[],"mappings":"AAGA,UAAU,eAAe,CAAC,CAAC;IACzB,wBAAwB;IACxB,GAAG,EAAE,MAAM,CAAC;IAEZ,4EAA4E;IAC5E,YAAY,CAAC,EAAE,CAAC,CAAC;IAEjB,oEAAoE;IACpE,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC,0EAA0E;IAC1E,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAE7B,uEAAuE;IACvE,WAAW,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;CAChC;AAkBD,wBAAgB,eAAe,CAAC,CAAC,GAAG,MAAM,EAAE,EAC1C,GAAG,EACH,YAAwB,EACxB,uBAA+B,EAC/B,WAA6B,EAC7B,SAAyB,GAC1B,EAAE,eAAe,CAAC,CAAC,CAAC,uCAQM,CAAC,KAAK,CAAC,YAoCjC;AAED,eAAO,MAAM,oBAAoB,wBAAkB,CAAC"}
|