I want to create searchable input but something went wrong that's why this is not working. How can I fix it?
My code:
import React, {useState} from 'react'; import "./styles.css"; export default function App() { const country_list = [ "Argentina", "Australia", "Belgium", "Belize", "China", "Iceland", "India", "Indonesia", "Iran", "Poland", "Portugal", "Romania", "Russia", "Saudi Arabia", "South Africa", "South Korea", "Swaziland", "Sweden", "Switzerland" ]; const [inputVal, setInputVal] = useState(); country_list.filter(country => { if(inputVal === ''){ return country; } else if (country.toLowerCase().includes(inputVal.toLowerCase())) { return country; } }); return ( <div className="App"> <input type="text" onChange={event => setInputVal(event.target.value)} /> {inputVal} {country_list.map((val, index)=>( <> <div key={index}> {val} </div> </> ))} </div>) }
filterto anything