I'm trying to do something in a personal React project. So, I have a list of locations and a search input. When I'm entering something in that input and nothing is found in my locations array I want to show a message like "No result found!". I know how to do this just when I don't use that filter thing.
Here is my code where I'm filtering results by that input:
<input
type="text"
placeholder="Cautare"
value={searchedLocation}
onChange={(e) => { setSearchedLocation(e.target.value); }}
/>
<div className="workspace">
<div className="locations-group">
{locations.filter((location) => {
if (searchedLocation === null) {
return location;
} else {
if(location.name.toLowerCase().includes(searchedLocation.toLowerCase()))
return location;
}
}).map((loc) => {
return <LocationModel locationName={loc.name} />
} )}
</div>
</div>