Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

351
Views
How to filter data and show in flatList (search flatlist) React Native

I am trying to search data and send that data to a flat list. The current code works without error however it only finds results with the an exact text searched. I am trying to filter data to give me results as long as the text that I am searching is found anywhere in the string. I need help with my handleSearch function

Example. When I search: "Good book". it finds results. If I search: "is a good book" I do not get any results

I would like to receive results for my string as long as the text is founded somewhere in the string

Example What I am hoping for. Find results if string contains: This is a Good book, or Good is a book.

// _.filter is a function I am using from Lodash
// action list is the data coming from another file: ActionListService.getList()
const ActionList = [
  {
    title: 'Good Book',
    icon: 'good book',
    action: 'good book',
  },
  {
    title: 'Hello World',
    icon: 'hello',
    action: 'hello action',
  },
]

const [isLoading, setIsLoading] = useState(false);
  const [query, setQuery] = useState('');
  const [fullData, setFullData] = useState([]);
  const [data, setData] = useState([]);

  useEffect(() => {
    setIsLoading(true);

    ActionListService.getList()
      .then(results => {
        setData(results);
        setFullData(results);
        setIsLoading(false);
      })
      .catch(err => {
        setIsLoading(false);
      });
  }, []);

  const handleSearch = text => {
    const formattedQuery = text.toLowerCase();
    const filteredData = _.filter(fullData, value => {
      return value.title.toLowerCase().includes(formattedQuery);
    });
    setData(filteredData);
    setQuery(text);
  };

  return (
    <>
      <Searchbar
        placeholder="Search"
        onChangeText={queryText => handleSearch(queryText)}
        value={query}
      />
      <View style={{paddingLeft: insets.left, paddingRight: insets.right}}>
        <FlatList
          data={data}
          numColumns={orientation.orientation ? 1 : 3}
          key={orientation.orientation ? 1 : 3}
          keyExtractor={item => item.title}
          renderItem={({item}) => (
            <List.Item
              onPress={() => createAction(item.action)}
              // eslint-disable-next-line react-native/no-inline-styles
              style={{
                width: orientation.orientation ? '100%' : '30%',
              }}
              title={item.title}
              left={() => <List.Icon icon={item.icon} />}
            />
          )}
        />
      </View>
    </>
  );
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!