【发布时间】:2020-06-14 21:48:36
【问题描述】:
当数据从 sortedData 属性删除到平面列表时,我的 react-native 平面列表不会重新呈现。我尝试使用 extraData 道具强制重新渲染,但这没有用。当我删除元素时,会出现空白行。
handleRemove = (title) => {
// const start = this.state.people.slice(0, index);
// const end = this.state.people.slice(index + 1);
// this.setState({
// people: start.concat(end),
// });
const filteredData = this.state.sortedData.filter(
(item) => item.title !== title
);
this.setState({ sortedData: filteredData });
};
render() {
const { sortedData } = this.state;
return (
<FlatList
data={sortedData}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item, index }) => (
<LeaderboardEntry
song={item}
handler={this.handler}
onRemove={() => this.handleRemove(item.title)}
/>
)}
/>
);
}
【问题讨论】:
标签: reactjs react-native react-native-flatlist