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