Reputation: 17
I am making a ListView in React Native and getting "Cannot call class as a function" error. I also tried adding "new" keyword before class but still the error was not solved. Following is my code:
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 );
You can see the error here. How do I solve it?
Upvotes: 1
Views: 877
Reputation: 8843
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'])
}
}
Upvotes: 4