I have a React Native ListView that seems to be removing the wrong row in the UI when I update the state with the new sections & rows - The row I deleted stays, but the one, or sometimes even, 2 below that gets removed until I reload the app.
What am I doing wrong?
constructor(props) {
super(props)
this.state = {
dataState: DataState.STATE_NOT_LOADED,
dataSource: new ListView.DataSource({
rowHasChanged: (r1, r2) => r1.identifier !== r2.identifier,
sectionHeaderHasChanged: (s1, s2) => s1 !== s2
})
};
}
componentDidMount() {
this.loadData();
}
loadData() {
this.setState({
dataState: DataState.STATE_LOADING
});
User.getDocs()
.bind(this)
.then(results => {
var docs = _.groupBy(results, function (d) {
return d.createdAt.format('MMMM D');
});
this.setState({
dataState: DataState.STATE_LOADED,
dataSource: this.state.dataSource.cloneWithRowsAndSections(docs)
});
})
.catch(error => {
console.log(error);
this.setState({
dataState: DataState.STATE_ERROR
});
});
}
onTrackPressed(doc) {
User.untrackDoc(doc)
.bind(this)
.tap(() => {
this.loadData();
});
}
renderRow(result) {
return (
<DocRow
style={styles.row}
doc={result}
tracked={true}
onPress={() => this.onRowPressed(result)}
onTrackPress={() => this.onTrackPressed(result)}/>
);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…