集成stream-chat-react-native遇_reactNativeReanimated.useSharedValue错误
错误原因
你当前使用的react-native-reanimated@1.13.4属于1.x版本,而stream-chat-react-native@5.15.1依赖Reanimated 2.x版本新增的useSharedValue钩子,二者版本不匹配导致了这个类型错误。
解决方案
步骤1:升级react-native-reanimated到兼容的2.x版本
针对你的React Native 0.62.3,推荐安装适配的2.x版本(如2.2.4,与RN0.62.x兼容性较好):
npm install react-native-reanimated@2.2.4 --save # 或使用yarn yarn add react-native-reanimated@2.2.4
步骤2:配置Reanimated 2.x的babel插件
在项目根目录的babel.config.js中,添加Reanimated插件到配置数组:
module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: ['react-native-reanimated/plugin'], };
步骤3:清理缓存并重建项目
# 清除npm/yarn缓存 npm cache clean --force # 或 yarn cache clean # 重置Metro缓存 npx react-native start --reset-cache # iOS项目重新安装依赖并构建 cd ios && pod install && cd .. npx react-native run-ios # Android项目直接重新构建 npx react-native run-android
额外提示
如果升级后出现其他兼容性问题,可核对stream-chat-react-native官方文档的依赖要求,确保react-native-gesture-handler等相关依赖也处于兼容版本。
内容的提问来源于stack exchange,提问作者Kaustubh
相关产品推荐
相关产品推荐

