Reputation: 17
I'm trying to update listview from a function, But currently it is not updating, Here is the complete source code.
Please also mention that what I am doing wrong
import React, { Component } from 'react';
import {
AppRegistry,
ListView,
TextView,
Text,
View
} from 'react-native';
const ds = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 != row2 });
var myarray = [];
export default class filesix extends Component {
constructor() {
super();
this.state = {
dataSource: ds.cloneWithRows(myarray),
};
console.log(`ds const =${myarray}`);
}
componentDidMount() {
myarray = ['11', '22'];
console.log(myarray);
this.setState = ({
datasource: this.state.dataSource.cloneWithRows(myarray),
});
this.prepareDataSource();
console.log('this componentDidMount');
}
prepareDataSource() {
myarray = ['11', '22'];
console.log(myarray);
}
renderRow(rowData) {
return <Text>{JSON.stringify(rowData)}</Text>
}
render() {
return (
<View style={{ flex: 1, borderWidth: 2 }}>
<ListView
enableEmptySections={true}
dataSource={this.state.dataSource}
renderRow={this.renderRow}
/>
</View>
);
}
}
AppRegistry.registerComponent('filesix', () => filesix);
I already spent my whole day to update the values, but no luck, Please correct my understanding.
Upvotes: 0
Views: 49
Reputation: 980
Your componentDidMount
has a typo. It's setting state on datasource
but your ListView is using dataSource
.
Upvotes: 1