简体   繁体   English

平台清单不会在状态更改时重新呈现

[英]Flatlist not rerendering on state change

I have a FlatList and it is not rerendering when a state change happens. 我有一个FlatList,状态更改发生时它不会重新呈现。 How do I get a FlatList to rerender? 如何获得要重新提交的FlatList?

 _renderItem = ({item}) => {
    if(item=='null'){
      return <Text>Item is null</Text>
    }else{
      return <Text>Item is not null</Text>
    }    
};

render(){
 return(
  <FlatList
   data={this.state.itemList}   
   renderItem={this._renderItem}      
  />

 )
}

Change your code to this: 将代码更改为此:

render(){
  return(
    <FlatList
      data={this.state.itemList}   
      extraData={this.state}
      renderItem={this._renderItem}      
    />
  )
}

The FlatList component needs extraData to be set to this.state so that it will update when it changes. FlatList组件需要将extraData设置为this.state,以便它在更改时进行更新。

See the documentation for more details: https://facebook.github.io/react-native/docs/flatlist.html 请参阅文档以获取更多详细信息: https : //facebook.github.io/react-native/docs/flatlist.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM