reactjs - TypeError: 'function' 不是 React Native 中的函数
问题描述
完整的错误是TypeError: doFollow is not a function. (In 'doFollow(index), 'doFollow is undefined)
我是 React Native 的新手,所以我不太确定问题可能是什么,代码如下:
render(){
const followReq = this.props.navigation.getParam('followRequest', '0')
const doFollow = this.props.navigation.getParam('doFollow', '')
return (
<View style={styles.container}>
{
followReq.map((frn, index) => (
<Button
key={frn}
title={`Follow ${frn}`}
onPress={() => doFollow(index)}
/>
))
}
</View>
);
}
解决方案
render(){
const followReq = this.props.navigation.getParam('followRequest', '0')
const doFollow = this.props.navigation.getParam('doFollow', '')
return (
<View style={styles.container}>
{ followReq.map((frn, index) => (
<Button
key={frn}
title={`Follow ${frn}`}
onPress={() => {
this.doFollow(index);}}/>)) }
</View>);}
推荐阅读
- ios - CocoaPods 找不到 pod“Firebase/Analytics”的兼容版本
- flutter - 在初始化期间读取静态变量 => Flutter Navigator.push
- mysql - 未选择数据库 双击选择要使用的默认数据库
- ios14 - 即使 UserDefaults 同步,小部件也不会更新
- php - 如何从 SQL 数据库中删除记录
- python - 使用列表打开 PYTHON 文件
- excel - Excel 不会将单元格视为空白
- sql-server - 如何在 SQL Server 中使用 SUM 更新获胜者“点”列
- javascript - 监听值事件时如何延迟加载?
- python - Python代码中的()有什么用?