diff --git a/bs3/src/App.js b/bs3/src/App.js index b4ba0ba..60cb16f 100644 --- a/bs3/src/App.js +++ b/bs3/src/App.js @@ -4,12 +4,18 @@ import { Outlet } from 'react-router-dom'; import { useDispatch } from 'react-redux'; import { setLocation } from './app/geolocatorSlice'; import useGeoLocationCheck from './api/geolocation'; +import { useEffect } from 'react'; function App() { - const dispatch = useDispatch(); - const geoLocation = useGeoLocationCheck(); - dispatch(setLocation(geoLocation)); + const geoLocation = useGeoLocationCheck(); // Custom hook + + // Use useEffect to dispatch the action only when geoLocation is valid + useEffect(() => { + if (geoLocation) { + dispatch(setLocation(geoLocation)); + } + }, [dispatch, geoLocation]); return (