Hard
You're building a search bar component that needs to suggest results as the user types. The component should minimize API calls and handle race conditions. What's missing in this implementation?
1function SearchBar({ onSearch }) {2 const [query, setQuery] = useState('');3 const [suggestions, setSuggestions] = useState([]);4 const [isLoading, setIsLoading] = useState(false);56 _______________78 const handleInputChange = (e) => {9 const value = e.target.value;10 setQuery(value);11 };1213 return (14 <div className="search-container">15 <input16 type="text"17 value={query}18 onChange={handleInputChange}19 placeholder="Search..."20 className={isLoading ? 'loading' : ''}21 />22 {suggestions.length > 0 && (23 <ul className="suggestions">24 {suggestions.map(item => (25 <li key={item.id} onClick={() => onSearch(item)}>26 {item.title}27 </li>28 ))}29 </ul>30 )}31 </div>32 );33}