TypeError Cannot read property 'getPlacePredictions' of null
abidRahim opened this issue · comments
I have integrated google-map-react with use-places-autocomplete hook.
From what i understand, on component mount this hook is not able to find the google.maps object
Error can be reproduced on searching with any key on input, in code-sandbox here: Code Sandbox example ->
What is the way around to fix this?
I had this problem when adding async defer
to my script tag.
Adding disabled={!ready}
to my input element and reloading, my form field was disabled and never enabled.
For the time being, I removed async defer
and now my form is enabled and I can pull suggested places.
Quick update for me, I was able to add back async defer
by ensuring that my script tag included &callback=initMap
at the end there.
That callback is used by this library in order to appropriately set that ready
state that I talked of prior.
In terms of your issue @abidRahim I can't see where you include the API in your sandbox, is that there? If so, does your script src include callback=initMap
?
@abidRahim It's because you pass the Google Map API before it's loaded. Please refer to this issue.