'filter data flatlist with react native

I have a SearchBar component that allows me to filter my data from my flatlist but that on the name field I would like to make it evolve so that it filters on the name field and the first name field how could I do that? thank you in advance.

  handleSearch = (searchText) => {
    if (searchText) {
      setState({ searchText: searchText });

      const filteredData = profil.filter((item) => {
        const itemData = item.data.name;
        const textData = searchText.toUpperCase();

        return itemData.includes(textData);
      });
      setFilterData(filteredData);
      setState({ query: searchText });
    } else {
      setFilterData(profil);
      setState({ query: searchText });
    }
  };


Solution 1:[1]

You could do this (declare a new variable for what you're searching for and then modify your return statement):

const firstNameData = item.data.firstName;

...

return itemData.includes(textData) || firstNameData.includes(textData);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 man517