在rn開發(fā)中,一個FlatList中數(shù)據(jù)用到mobx,遇到下圖中的警告

Simulator Screen Shot - iPhone 6 - 2018-01-08 at 11.44.31.jpg
查到下面的issues解決了問題,就是不要直接使用mobx的數(shù)據(jù),slice一下就沒有警告了;
Issues鏈接
<FlatList
data={historyStore.historyData}
renderItem={this.renderItem}/>
historyData為mobx數(shù)據(jù),作如下改動,就沒有警告了
<FlatList
data={historyStore.historyData.slice()}
renderItem={this.renderItem}/>
但是如果是SectionList,其數(shù)據(jù)結構是多維數(shù)組,只是在調用mobx數(shù)據(jù)時slice一下依然會有警告,因為其數(shù)據(jù)內部的數(shù)組依然是mobx數(shù)據(jù),此種情況可使用computed改造數(shù)據(jù),代碼如下:
//class GroupChatListStore
@observable sectionData = [
{
key: "臨時群組",
data: [0,1,2 ]
},
{
key: "我的圈子",
data: [0,1,2]
}
];
@computed get formattedList(){
return this.sectionData.map((v)=>{
return {
key: v.key,
data: v.data.slice(),
}
}).slice();
}
//使用方法
<SectionList sections={groupChatListStore.formattedList}/>