Use useEffect for side effect
This commit is contained in:
@@ -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 {useSyncDeviceGeolocationOnStartup} from '#/geolocation/device'
|
||||||
import {useGeolocationServiceResponse} from '#/geolocation/service'
|
import {useGeolocationServiceResponse} from '#/geolocation/service'
|
||||||
@@ -35,11 +41,13 @@ export function Provider({children}: {children: ReactNode}) {
|
|||||||
'deviceGeolocation',
|
'deviceGeolocation',
|
||||||
])
|
])
|
||||||
const geolocation = useMemo(() => {
|
const geolocation = useMemo(() => {
|
||||||
const merged = mergeGeolocations(deviceGeolocation, geolocationService)
|
return mergeGeolocations(deviceGeolocation, geolocationService)
|
||||||
device.set(['mergedGeolocation'], merged)
|
|
||||||
return merged
|
|
||||||
}, [deviceGeolocation, geolocationService])
|
}, [deviceGeolocation, geolocationService])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
device.set(['mergedGeolocation'], geolocation)
|
||||||
|
}, [geolocation])
|
||||||
|
|
||||||
useSyncDeviceGeolocationOnStartup(setDeviceGeolocation)
|
useSyncDeviceGeolocationOnStartup(setDeviceGeolocation)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user