我无法使用 react native autocomplete npm 包,我收到了这个错误“react-native-google-places-autocomplete unable to resolve module path/custom/left-icon
”
我正在使用 React Native V0.44.0
我做错了什么?
import React from 'react';
import { View, Image } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
const homePlace = { description: 'Home', geometry: { location: { lat: 48.8152937, lng: 2.4597668 } }};
const workPlace = { description: 'Work', geometry: { location: { lat: 48.8496818, lng: 2.2940881 } }};
const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder='Search'
minLength={2}
autoFocus={false}
returnKeyType={'search'}
listViewDisplayed='auto'
fetchDetails={true}
renderDescription={(row) => row.description}
onPress={(data, details = null) => {
console.log(data);
console.log(details);
}}
getDefaultValue={() => {
return '';
}}
query={{
key: 'YOUR API KEY',
language: 'en',
types: '(cities)'
}}
styles={{
description: {
fontWeight: 'bold'
},
predefinedPlacesDescription: {
color: '#1faadb'
}
}}
currentLocation={true}
currentLocationLabel="Current location"
nearbyPlacesAPI='GooglePlacesSearch'
GoogleReverseGeocodingQuery={{
}}
GooglePlacesSearchQuery={{
rankby: 'distance',
types: 'food'
}}
filterReverseGeocodingByTypes={['locality', 'administrative_area_level_3']}
predefinedPlaces={[homePlace, workPlace]}
debounce={200}
renderLeftButton={() => <Image source={require('path/custom/left-icon')} />}
renderRightButton={() => <Text>Custom text after the inputg</Text>}
/>
);
}
最佳答案
把线拿出来
renderLeftButton={() => <Image source={require('path/custom/left-icon')} />}
或将其替换为文本或您自己的图像。您应该将该路径替换为您自己的文本或图像,或者如果您不需要它,您应该将其完全删除。
例如试试这个:
renderLeftButton={() => <Text> Left Button or Left Icon </Text>}
关于react-native-google-places-autocomplete 无法解析模块 `path/custom/left-icon`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48255203/