I want to filter the data in a FlatList of react-native,
I have several filters,
The first is easy a word, the second filter (independent of the previous one) a list (array) of tags.
The data
Array [
Object {
"ID": 1,
"name": "Name 1",
"tags": Array [
Object {
"ID": 1,
"name": "tag 1",
},
Object {
"ID": 2,
"name": "tag 2",
},
],
},
Object {
"ID": 2,
"name": "Name 2",
"tags": Array [
Object {
"ID": 1,
"name": "tag 1",
},
],
},
]
The React Native component
searchedText = "string" works well & selectedTags = [] like key tags described above
<FlatList
data={
filterType === null ? items
: filterType === "text" ? items.filter(item => item.name.includes(searchedText))
: filterType === "tags" ? items.filter(item => item.tags.includes(selectedTags))
: null
}
keyExtractor={( item ) => item.ID.toString() }
renderItem={ ({ item }) => <AnotherComponent item={ item }/> }
/>
I do not know how to work deeply, Do you have a solution to filter the selected tag(s)?
Like :
items.filter(item => item.tags.includes([{name:"tag1"},{name:"tag2"}]))
Array > Array