I am actually using a search function to search in a list (data), the thing is it's showing all the information in the list by default. How can I hide all the list ? And show it (the results) only once the user typed something in the search input.
Thanks in advance,
Code that I am using :
const [search, setNewSearch] = useState("");
const handleSearchChange = (e) => {
setNewSearch(e.target.value);
};
const filtered = !search
? data
: data.filter((item) =>
item.titre.toLowerCase().includes(search.toLowerCase())
);
return view :
<TextInput style={styles.search}
value={search}
onChange={handleSearchChange}
></TextInput>
<Text style={styles.text}>Résultat rapide :</Text>
<View style={styles.text}>
{filtered.map((item) => {
return (
<p key={item.id}>
Nom: {item.titre}
- Date: {item.date}
- Rating: {item.note}/10
</p>
);
})}
</View>
image of the app : see image