You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

react-native-google-places-autocomplete v2.5.7异常:filter报错与props添加后失效

react-native-google-places-autocomplete v2.5.7 故障排查与解决

问题现象

  • 使用react-native-google-places-autocomplete v2.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 01:25:56