MCPcopy Create free account
hub / github.com/electric-sql/electric / useSyncStatus

Function useSyncStatus

examples/linearlite/src/sync.ts:262–286  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

260}
261
262export function useSyncStatus() {
263 const currentSyncStatusJson = localStorage.getItem(`syncStatus`)
264 const currentSyncStatus: [SyncStatus, string] = currentSyncStatusJson
265 ? JSON.parse(currentSyncStatusJson)
266 : [`initial-sync`, `Starting sync...`]
267 const [syncStatus, setSyncStatus] =
268 useState<[SyncStatus, string]>(currentSyncStatus)
269
270 useEffect(() => {
271 const handleStorageChange = (e: StorageEvent) => {
272 if (e.key === `syncStatus` && e.newValue) {
273 const [newStatus, message] = JSON.parse(e.newValue)
274 setSyncStatus([newStatus, message])
275 }
276 }
277
278 window.addEventListener(`storage`, handleStorageChange)
279
280 return () => {
281 window.removeEventListener(`storage`, handleStorageChange)
282 }
283 }, [])
284
285 return syncStatus
286}
287
288let initialSyncDone = false
289

Callers 1

AppFunction · 0.90

Calls 2

getItemMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected