(key: string = "state", state: any)
| 15 | }; |
| 16 | |
| 17 | export const saveState = (key: string = "state", state: any) => { |
| 18 | try { |
| 19 | const seen: any = []; |
| 20 | const serializedState = JSON.stringify(state, (key, val) => { |
| 21 | if (val !== null && typeof val === "object") { |
| 22 | if (seen.indexOf(val) >= 0) { |
| 23 | return; |
| 24 | } |
| 25 | seen.push(val); |
| 26 | } |
| 27 | return val; |
| 28 | }); |
| 29 | setItem(key, serializedState); |
| 30 | } catch (err) { |
| 31 | // Ignore write errors. |
| 32 | console.error(err); |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | export function putState( |
| 37 | key: string = "state", |