React-native-google-places-autocomplete: getDefaultValue not rerender with state value change

Created on 6 Jun 2017  路  11Comments  路  Source: FaridSafi/react-native-google-places-autocomplete

We are using RN: 0.40.0.
Is there any way by which we rerender default value after first time render ?
We are trying to update default value in GooglePlacesAutocomplete "getDefaultValue" attribute by changing state value.

Can anyone suggest any solution?

Most helpful comment

You can use setAddressText("...").

On your autocomplete component get a reference to the object:
<GooglePlacesAutocomplete ref={(instance) => { this.locationRef = instance }} .../>

and then:
this.locationRef.setAddressText("New York, NY")

All 11 comments

Same problem here

Ok i wrapped a condition around so that it renders only when the default value is ready. Not an elegant way and probably does not cover you need, but works for me for now.

{this.props.defaultValueReady ? (
    <GooglePlacesAutocomplete
         query={{
         ...
     />
) : <View></View>}    

@MSSPL-PiyaleeMaiti but i think all in all you are right there is no way of setting the autocomplete input field later on from outside/state you can just set it by typing text as i understood

Are you still working on this? I have the same issue

You can use setAddressText("...").

On your autocomplete component get a reference to the object:
<GooglePlacesAutocomplete ref={(instance) => { this.locationRef = instance }} .../>

and then:
this.locationRef.setAddressText("New York, NY")

Thanks that worked!

@noambonnie Thanks it worked

@noambonnie I can麓t get it to work, when I try this:

ref={(instance) => { this.GooglePlacesRef = instance }}
getDefaultValue={() => {
this.GooglePlacesRef.setAddressText("Something")
}}

I get an error Cannot read property 'setAddressText' of undefined

@noambonnie Thanks a TON !! Saved my day :)

You can use setAddressText("...").

On your autocomplete component get a reference to the object:
<GooglePlacesAutocomplete ref={(instance) => { this.locationRef = instance }} .../>

and then:
this.locationRef.setAddressText("New York, NY")

Where to do this after setting reference?

this.locationRef.setAddressText("New York, NY")

@NeenaMishra12 see this example.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sohel-tech picture sohel-tech  路  3Comments

aymkin picture aymkin  路  4Comments

lukBakTsh picture lukBakTsh  路  3Comments

miguel-pm picture miguel-pm  路  3Comments

mbelgrader picture mbelgrader  路  4Comments