react-native-google-places-autocomplete v2.5.7异常:filter报错与props添加后失效
react-native-google-places-autocomplete v2.5.7 故障排查与解决
问题现象
- 使用
react-native-google-places-autocompletev2.5.7时出现报错:cannot read property filter of undefined - 添加
predefinedPlaces={[]}属性后报错消失,但组件依然无法正常运行 - 已验证API请求能成功返回数据,且v1.8.1旧版本可正常使用
解决方法
1. 回退至稳定版本
直接切换到已知可用的v1.8.1版本,快速恢复功能:
npm uninstall react-native-google-places-autocomplete npm install react-native-google-places-autocomplete@1.8.1
2. 新版本适配排查(若需保留v2.5.7)
- 核对所有必填配置项(如
apiKey、query)是否完整且正确,避免因缺失参数导致内部逻辑异常 - 检查React Native版本与v2.5.7的兼容性,参考包官方文档确认适配范围
- 清理项目缓存并重新安装依赖:
npx react-native start --reset-cache rm -rf node_modules && npm install - 尝试补充配置
predefinedPlacesAlwaysVisible={false},配合predefinedPlaces={[]}使用,覆盖组件内部默认逻辑
内容的提问来源于stack exchange,提问作者R. Ekrem ÇOBAN
相关产品推荐
相关产品推荐

