question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: setaddressText using ref should trigger search

See original GitHub issue

Describe 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:open
  • Created 3 years ago
  • Reactions:5
  • Comments:12

github_iconTop GitHub Comments

5reactions
icomadcommented, Oct 4, 2021

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 inside react-native-google-places-autocomplete in node_modules. The problem seems to be that the useEffect at line 145 that is in charge of populating the results list runs before the local state variable stateText is updated from the setAddressText method. If you change line 161 from setStateText(address) to _handleChangeText(address) it should work.

4reactions
bell-stevencommented, Nov 12, 2020

Ok. Can you try using version 2.1.1. There were some changes in v2.1.0 that may have addressed the issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found