記錄問題,在react-native中使用FlatList渲染每個(gè)Item的時(shí)候,item中的一個(gè)值需要來判斷這個(gè)文字顯示,是關(guān)注還是已關(guān)注,所以點(diǎn)擊時(shí)需要直接更改數(shù)組中的一個(gè)屬性值。
state = {
UserList : []
}
const UserList = [...this.state.UserList] //復(fù)制數(shù)組
const index = item.index
this.setState({
UserList: UserList.map((item, idx) => idx === index ? {...item, fansId: ""} : item)
})