首页 > 解决方案 > 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> 
    );
  }

标签: reactjsreact-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={() => {
                  this.doFollow(index);}}/>)) }
   </View>);}

推荐阅读