大家好
我正在React Native上开发一个天气应用程序。在我的项目中,我安装了react原生谷歌位置自动完成
我从文档中提取了一个基本示例的代码,并将其插入到我的应用程序中:
import React from 'react';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
export const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder='Search'
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
query={{
key: 'my key here...',
language: 'en',
}}
/>
);
}
屏幕截图
万岁,一切都好。但由于某些原因,搜索栏无法点击。我点击它,但什么也没发生,我不能在那里写作。
请告诉我可能出了什么问题
也许你需要这个:
const ref = useRef();
useEffect(() => {
ref.current?.setAddressText('Some Text');
}, []);
然后在你看来:
<GooglePlacesAutocomplete
ref={ref}
...
/>