ErrorPro / react-google-autocomplete

React components for google places API.
MIT License
462 stars 114 forks source link

placesService.getDetails is undefined #233

Open isaacfink opened 4 months ago

isaacfink commented 4 months ago

I am creating my instance like this

const {
        placePredictions,
        getPlacePredictions,
        isPlacePredictionsLoading,
        placesService
    } = useGoogle({
        apiKey: process.env.NEXT_PUBLIC_GOOGLE_PLACES_API_KEY,
    });

And calling the placesService like this

const getPlaceInfo = async (placeId) => {
        console.log(placesService)
        const info = await placesService.getDetails({ placeId })
    }

But in the console I see this {Fg: F$} and getDetails is undefined, I am not sure where this is coming from, it might have something to do with the bundler but it seems like the returned object is wrong

ozergul commented 3 months ago

use with useCallback and add placesService as deps. issue will be fixed.

  const getPlaceInfo = useCallback(async (placeId) => {
    console.log(placesService);
    const info = await placesService.getDetails({ placeId });
  }, [placesService]
jamesofficer commented 2 months ago

I resolved this by passing a callback as the second parameter.

placesService.getDetails({ placeId }, (response: any) => {
    console.log("response", response);
});