gpt4 book ai didi

android - Cannot call class as a function 错误在 React Native 中

转载 作者:行者123 更新时间:2023-11-29 15:39:05 25 4
gpt4 key购买 nike

我在 React Native 中制作一个 ListView 并收到“无法将类作为函数调用”错误。我也尝试在课前添加“new”关键字,但错误仍未解决。以下是我的代码:

import React, {Component} from 'react';
import {StyleSheet, View, AppRegistry, ListView, Text} from 'react-native';

class listview extends Component{

constructor(props){
super(props);
var ds = ListView.DataSource({rowHasChanged : (r1,r2) => r1!==r2});
this.state = {
dataSource: ds.cloneWithRows(['1','2','3','4'])
}
}

_renderRow(rowData){
return <Text>{rowData}</Text>;
}

render(){
return(
<ListView
dataSource = {this.state.dataSource}
renderRow = {this._renderRow.bind(this)}
/>
);
}
}
AppRegistry.registerComponent('listview', () => listview );

可以看到错误here .我该如何解决?

最佳答案

constructor(props){
super(props);
var ds = new ListView.DataSource({rowHasChanged : (r1,r2) => r1!==r2});
//-------^^^ you forgot to place `new` keyword here.
this.state = {
dataSource: ds.cloneWithRows(['1','2','3','4'])
}
}

关于android - Cannot call class as a function 错误在 React Native 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44450967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com