我有一个工作 <TextInput>
:
<TextInput
placeholder="Location"
value={props.locationInput.toString()}
onChangeText={location => props.updateLocationInput(location)}
/>
props.locationInput
最初是 ''
但是一旦应用程序启动,就会触发几个异步函数并获取用户当前位置,该位置填充 props.locationInput(在 redux 存储中)。这意味着 <TextInput>
上面显示用户到达时的当前位置。我想基本上完全按照上面的方式做,但是使用 react-native-google-places-autocomplete
react-native-google-places-autocomplete
确实使用 props.locationInput 值进行初始化。它有一个 getDefaultValue
属性(property)例如getDefaultValue={() => props.locationInput.toString()}
,但是当 props.locationInput 改变时它不会改变,所以它永远不会显示用户当前位置,因为它在初始化时没有设置。我如何获得 react-native-google-places-autocomplete
何时更新 props.locationInput
变化?
可能认为我可能需要在用户当前位置进来之前不渲染它,但这真的很乱。
编辑:同时考虑不使用插件,而是调用 google places API。
最佳答案
比赛晚了,但有一个名为 setAddressText 的函数.
例子:
setLocation(text) {
this.placesRef && this.placesRef.setAddressText(text)
}
...
<GooglePlacesAutocomplete
ref={ref => {this.placesRef = ref}}
...
/>
关于javascript - react-native-google-places-autocomplete 给它一个值而不仅仅是默认(初始)值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43776697/