Use useEffect for side effect

This commit is contained in:
Eric Bailey
2025-12-04 09:55:46 -06:00
parent c5646cbb21
commit 41c68b1513
+12 -4
View File
@@ -1,4 +1,10 @@
import {createContext, type ReactNode, useContext, useMemo} from 'react'
import {
createContext,
type ReactNode,
useContext,
useEffect,
useMemo,
} from 'react'
import {useSyncDeviceGeolocationOnStartup} from '#/geolocation/device'
import {useGeolocationServiceResponse} from '#/geolocation/service'
@@ -35,11 +41,13 @@ export function Provider({children}: {children: ReactNode}) {
'deviceGeolocation',
])
const geolocation = useMemo(() => {
const merged = mergeGeolocations(deviceGeolocation, geolocationService)
device.set(['mergedGeolocation'], merged)
return merged
return mergeGeolocations(deviceGeolocation, geolocationService)
}, [deviceGeolocation, geolocationService])
useEffect(() => {
device.set(['mergedGeolocation'], geolocation)
}, [geolocation])
useSyncDeviceGeolocationOnStartup(setDeviceGeolocation)
return (