Closed Raghavj2000 closed 2 months ago
Can you provide the code you used to search?
const selectCountry = (country) => { setSelectedCountry(country); setIsOpen(false); setPhoneNumber(country.dialCode); };
const renderCountryFlags = () => { const filteredCountries = countries.filter((country) => country.name.toLowerCase().includes(searchQuery.toLowerCase()) );
const sortedCountries = filteredCountries.sort((a, b) => {
const aIndex = a.name.toLowerCase().indexOf(searchQuery.toLowerCase());
const bIndex = b.name.toLowerCase().indexOf(searchQuery.toLowerCase());
// Sort by the index of the search query in the country name
if (aIndex < bIndex) return -1;
if (aIndex > bIndex) return 1;
// If the index is the same, sort by the length of the country name
if (a.name.length < b.name.length) return -1;
if (a.name.length > b.name.length) return 1;
return 0;
});
const findByKeyword = (keyword) => {
return sortedCountries.filter(
(country) =>
country.name.toLowerCase().includes(keyword.toLowerCase()) ||
country.code.toLowerCase().includes(keyword.toLowerCase())
);
};
const foundCountries = findByKeyword(searchQuery);
return foundCountries.map((country) => {
const flagSvg = CountryFlagSvg[country.code];
const flagString = flagSvg && flagSvg.toString();
the problem is if i search India, all country that has letter I or letter N or A appears.
import CountryList from 'country-list-with-dial-code-and-flag'
CountryList.findByKeyword('india')
When i search for a flag still random flag appears