Feature Request: setaddressText using ref should trigger search
See original GitHub issueDescribe the bug
I am saving recently searched terms in my state and when user clicks on one of the recent searches, I do this.autoCompleteRef.setAddressText(this.state.recentSearch). This updates the text input value but the search is not triggered. I have to press one more key to see the search results from place autocomplete api
Reproduction - (required - issue will be closed without this)
Steps to reproduce the behavior - a minimal reproducible code example, link to a snack or a repository.
Please provide a FULLY REPRODUCIBLE example.
Click to expand!
<GooglePlacesAutocomplete
ref={comp => (this.autoCompleteRef = comp)}
placeholder="Search"
styles={{textInput: {borderBottomColor: "#4a4a4a", borderBottomWidth: 1, backgroundColor: 'transparent'}}}
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data);
console.log(details);
}}
query={{
key: 'key',
language: 'en',
components: 'country:in',
}}
currentLocation={true}
currentLocationLabel="Use your current location"
nearbyPlacesAPI="GoogleReverseGeocoding"
textInputProps={{onBlur: () => {}}}
fetchDetails //details.geometry.location - gives lat, lng
/>
handleRecentLocationClick = (desc) => {
this.autoCompleteRef.setAddressText(desc)
this.autoCompleteRef.focus()
}
Please remember to remove you google API key from the code you provide here
Additional context
-
Library Version: [e.g. 1.4.2]
-
React Native Version: [e.g. 0.62.2]
-
iOS
-
Android
-
Web
If you are using expo please indicate here:
- I am using expo
Add any other context about the problem here, screenshots etc
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:12
Top Results From Across the Web
In react-native-google-places-autocomplete , there is a ...
The setAddressText method they offer successfully prefills the input, but it does not trigger the search, so no dropdown options open. Only once ......
Read more >Using Google Places autocomplete components in React Native
The Places API primarily gives you information about places using HTTP requests. You can get all the information you need about a local...
Read more >react-native-google-places-autocomplete - Bountysource
autoCompleteRef.setAddressText(this.state.recentSearch). This updates the text input value but the search is not triggered. I have to press one more key to ...
Read more >react-native-google-places-autocomplete - npm
Step 3. Enable "Google Maps Geocoding API" if you want to use GoogleReverseGeocoding for Current Location. Basic Example. Basic Address Search.
Read more >Google Maps Search Component for React Native - Morioh
If set to false, a WIFI location will be requested. use GPS or not. ... return ( <GooglePlacesAutocomplete ref={ref} placeholder='Search' onPress={(data, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone still having trouble with this I managed to make it work. I’m on version 2.4.1 and you need to change a line in
GooglePlacesAutocomplete.js
insidereact-native-google-places-autocomplete
innode_modules
. The problem seems to be that theuseEffect
at line 145 that is in charge of populating the results list runs before the local state variablestateText
is updated from thesetAddressText
method. If you change line 161 fromsetStateText(address)
to_handleChangeText(address)
it should work.Ok. Can you try using version 2.1.1. There were some changes in v2.1.0 that may have addressed the issue.