@deix/rossini-core 1.0.4 → 1.0.5

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/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deix/rossini-core",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "lib/src/index.js",
5
5
  "type": "commonjs",
6
6
  "repository": {
@@ -5,6 +5,6 @@
5
5
  * @param {T} defaultValue the default value
6
6
  * @param {"local" | "session"} storage the type of storage where to persist the state
7
7
  */
8
- declare function usePersistedState<T>(name: string, defaultValue: T, storage?: "local" | "session"): [T, (value: T) => void];
8
+ declare function usePersistedState<T>(name: string, defaultValue: T, storage?: 'local' | 'session'): [T, (value: T) => void];
9
9
  export default usePersistedState;
10
10
  //# sourceMappingURL=usePersistedState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePersistedState.d.ts","sourceRoot":"","sources":["../../../../src/utils/hooks/usePersistedState.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,iBAAS,iBAAiB,CAAC,CAAC,EAC1B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,EACf,OAAO,GAAE,OAAO,GAAG,SAAmB,GACrC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CA8CzB;AAED,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"usePersistedState.d.ts","sourceRoot":"","sources":["../../../../src/utils/hooks/usePersistedState.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,iBAAS,iBAAiB,CAAC,CAAC,EAC1B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,EACf,OAAO,GAAE,OAAO,GAAG,SAAmB,GACrC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAwDzB;AAED,eAAe,iBAAiB,CAAC"}
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const storageMap = {
5
- local: "localStorage",
6
- session: "sessionStorage",
5
+ local: 'localStorage',
6
+ session: 'sessionStorage',
7
7
  };
8
8
  /**
9
9
  * Use a variable stored persistently on local storage.
@@ -12,12 +12,12 @@ const storageMap = {
12
12
  * @param {T} defaultValue the default value
13
13
  * @param {"local" | "session"} storage the type of storage where to persist the state
14
14
  */
15
- function usePersistedState(name, defaultValue, storage = "local") {
15
+ function usePersistedState(name, defaultValue, storage = 'local') {
16
16
  const [value, setValue] = (0, react_1.useState)(defaultValue);
17
17
  const firstRender = (0, react_1.useRef)(true);
18
18
  (0, react_1.useEffect)(() => {
19
19
  try {
20
- if (storage === "local") {
20
+ if (storage === 'local') {
21
21
  const localValueString = window.localStorage.getItem(name);
22
22
  if (localValueString) {
23
23
  const localValue = JSON.parse(localValueString);
@@ -34,7 +34,7 @@ function usePersistedState(name, defaultValue, storage = "local") {
34
34
  }
35
35
  catch (err) {
36
36
  console.log(err);
37
- if (storage === "local") {
37
+ if (storage === 'local') {
38
38
  window.localStorage.removeItem(name);
39
39
  }
40
40
  else {
@@ -48,11 +48,15 @@ function usePersistedState(name, defaultValue, storage = "local") {
48
48
  return;
49
49
  }
50
50
  try {
51
- if (storage === "local") {
52
- window.localStorage.setItem(name, JSON.stringify(value));
51
+ if (storage === 'local') {
52
+ window.localStorage.setItem(name, JSON.stringify(value, (_k, v) => {
53
+ return v === undefined ? null : v;
54
+ }));
53
55
  }
54
56
  else {
55
- window.sessionStorage.setItem(name, JSON.stringify(value));
57
+ window.sessionStorage.setItem(name, JSON.stringify(value, (_k, v) => {
58
+ return v === undefined ? null : v;
59
+ }));
56
60
  }
57
61
  }
58
62
  catch (err) {