(newValue: T | ((val: T) => T))
| 26 | |
| 27 | // Wrap the original setValue to emit events |
| 28 | const setValue = (newValue: T | ((val: T) => T)) => { |
| 29 | if (typeof newValue === "function") { |
| 30 | const updater = newValue as (val: T) => T; |
| 31 | const nextValue = updater(value); |
| 32 | setValueOriginal(nextValue); |
| 33 | storageEventChannel.emit(key, JSON.stringify(nextValue)); |
| 34 | } else { |
| 35 | setValueOriginal(newValue); |
| 36 | storageEventChannel.emit(key, JSON.stringify(newValue)); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | useEffect(() => { |
| 41 | // Listen for both storage events (cross-window) and custom events (same-window) |
no outgoing calls
no test coverage detected
searching dependent graphs…