Reputation: 89
const filterCountry = (event) => {
console.log('input', event.target.value)
const new_countries = countries.filter(country=> country.name.official.includes(event.target.value));
setCountries(new_countries)
}
Above being my filtering function to get value matching result from Rest Countries API from axios "https://restcountries.com/v3.1/all". PROBLEM is: missing results. With input 'sw', I shall have 'Botswana, Swaziland, Sweden, Swizerland', but now only 'Botswana,Eswatini', wrong result. Can you tell where is the problem ?
Upvotes: 0
Views: 192
Reputation: 13245
The issue is that the includes is case-sensitive.
Convert both the search text and values to lower case first in filter
.
country.name.official.toLowerCase().includes(event.target.value.toLowerCase())
Upvotes: 1