2

I have a FlatList which is sourced by an array defined in the view's state. The list is filtered by filtering the original array and setting the array in the state with the new filtered array. But the re-render is only called when the list is scrolled. Is there a way to force re-render flatlists ?

import setsArr from '../../json/sets';
.
.
.
constructor (props) {
  super(props);
  this.state({
    arrToDisplay: setsArr,
  });
}
.
.
.
_filter = (filter,value) => {
  var newArr = setsArr.filter(function(){
                 return (el.filter === value)
               });
  this.setState({
    arrToDisplay: newArr, 
  });
}

renderOption = (data) => {
  return (
    <Text>{data.item.name}</Text>
  );
}
render () {
   return (
      .
      .
      .
      <FlatList
        data={this.state.arrToDisplay}
        renderItem={(item) => this.renderOption(item)}}/>
      .
      .
   );
}
Dan Philip Bejoy
  • 4,321
  • 1
  • 18
  • 33

1 Answers1

0

I found with ListView, FlatList, and SectionList, that changes to the datasource only rendered when the FlatList had a unique key.

I'll be happy if someone posts a proper answer but this is what I'm doing now:

<FlatList
  key={"mylist" + hashOfDataSourceObj}
  ...

see https://stackoverflow.com/a/31481960/7223

navicore
  • 1,979
  • 4
  • 34
  • 50