我在 React Native 中制作了一个简单的 ListView。我收到错误,如下所示。我在网上搜索,但找不到相关帖子。代码如下。
import React, {Component} from "react";
import {StyleSheet, View, AppRegistry, ListView, Text} from "react-native";
class dhrumil extends Component{
constructor(props){
super(props);
this.state = {
var ds = new ListView.DataSource({rowsHasChanged : (r1,r2) => r1!==r2})
return {
dataSource: ds.cloneWithRows(["1","2","3","4","5"])
};
}
}
_renderer(rowData){
return <Text>{rowData}</Text>;
}
render(){
return(
<ListView
dataSource = {() => this.state.dataSource}
renderRow = {() => this._renderer()}
/>
);
}
}
AppRegistry.registerComponent("dhrumil",()=>dhrumil);
我该如何解决?
你在构造函数中编写了错误的编码
constructor(props) {
super(props);
var ds = new ListView.DataSource({rowsHasChanged : (r1,r2) => r1!==r2})
this.state = {
dataSource: ds.cloneWithRows(["1","2","3","4","5"])
};
}