React native 禁止更新ListView中已渲染组件的道具

React native 禁止更新ListView中已渲染组件的道具,react-native,React Native,我在一个组件中有一个列表视图,在该组件上,在场景加载后很快就会调用设置状态,在此设置状态下,我传递一个新的数据源数组,该数组类似于前一个数组,但前面有一个元素。所以react会重新呈现列表视图,但问题是它通过对道具或行的级联更新来实现这一点。以下是示例: 我有一个列表视图: <Component someProp=B /> // instance ID 1 <Component someProp=C /> // instance ID 2 <Component so

我在一个组件中有一个
列表视图
,在该组件上,在场景加载后很快就会调用
设置状态
,在此设置状态下,我传递一个新的数据源数组,该数组类似于前一个数组,但前面有一个元素。所以react会重新呈现
列表视图
,但问题是它通过对道具或行的级联更新来实现这一点。以下是示例:

我有一个列表视图:

<Component someProp=B /> // instance ID 1
<Component someProp=C /> // instance ID 2
<Component someProp=D /> // instance ID 3
<Component someProp=A /> // instance ID 1
<Component someProp=B /> // instance ID 2
<Component someProp=C /> // instance ID 3
<Component someProp=D /> // instance ID 4
所以这就造成了一个糟糕的情况:当从远程服务器获取完成时,这个组件可能已经收到了新的someProp,所以新的数据被推送到了错误的组件实例中。当然,我可以在
组件willreceiveprops
中再次请求新的数据,但这会带来太多的开销


有没有办法告诉react,当我的组件已经构建时,不应该接收新的道具?因此,它会在其他组件之前创建新组件,而不是更新所有组件的道具。或者有其他方法可以解决我的问题吗?

通过这种方法,它将区分数据列表以决定是否重新渲染

 import {ListView} from react-native'
 const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});

 //first concat old data with the new one
 let concatedData = this.state.dataSource.concat(newData);

 //then call this to update the listview
 this.setState({
     dataSource:ds.cloneWithRows(concatedData)
   });

这样,它将区分数据列表以决定是否重新渲染

 import {ListView} from react-native'
 const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});

 //first concat old data with the new one
 let concatedData = this.state.dataSource.concat(newData);

 //then call this to update the listview
 this.setState({
     dataSource:ds.cloneWithRows(concatedData)
   });

您能否显示组件将接收道具?你是在那里也做异步获取还是只做构造函数?@FuzzyTree我也在那里做异步和同步获取,是的,但是另一个数据。你能显示
组件WillReceiveProps吗?你是在那里做异步获取还是只做构造函数?@FuzzyTree我也在那里做异步和同步获取,是的,但是是另一个数据。是的,这是我现在做更新的方式,只是我没有附加,而是预先加上
newData
。是的,这是我现在做更新的方式,只是我没有附加,但是在新数据前加上前缀
newData