title: How can I include "Geolocation.watchPosition" in a hook that returns the user's current location?
body: <p>I am building a hook to watch the current location of the user.  However, I am not sure how the location update is triggered, as I do not include an argument in the hook.</p>
  <p>Does the following hook ensure that the user's location is constantly updated, or only when the component is mounted?</p>
  <pre><code>import Geolocation from &quot;@react-native-community/geolocation&quot;;
  
  const useGetUserLiveLocation = () =&gt; {
      const [isLoading, setIsLoading] = useState(true);
      const [userLiveLocation, setuserGetUserLiveLocation] = useState(undefined);
      const [error, setError] = useState(undefined);
      LogBox.ignoreLogs([&quot;new NativeEventEmitter&quot;]); // Ignore log notification by message
  
      useEffect(() =&gt; {
          try {
              request(
                  Platform.select({
                      android: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
                      ios: PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
                  })
              ).then((res) =&gt; {
                  if (res == &quot;granted&quot;) {
                      Geolocation.watchPosition(
                          (position) =&gt; {
                              var region = new Object();
                              region.latitude = position.coords.latitude;
                              region.longitude = position.coords.longitude;
                              region.latitudeDelta = 0.009;
                              region.longitudeDelta = 0.009;
                              setuserGetUserLiveLocation(region);
  
                              setIsLoading(false);
                          },
                          (error) =&gt; {
                              setError(&quot;Location is not enabled&quot;);
                              setIsLoading(false);
                          }
                      );
                  } else {
                      // console.log(&quot;Location is not enabled&quot;);
                      setError(&quot;Location is not enabled&quot;);
                      setIsLoading(false);
                  }
              });
          } catch (error) {
              console.log(&quot;location set error:&quot;, error);
              setError(&quot;Location is not enabled&quot;);
              setIsLoading(false);
          }
      }, []);
  
      return { userLiveLocation, error, isLoading };
  };
  
  const ExampleComponent=()=&gt;{
  
  // should return current location also when user location changes
  const { userLiveLocation, error, isLoading } = useGetUserLiveLocation()
  
  return null
  }
  
  </code></pre>