"use client"; import styles from "../styles/search.module.css"; import { FaSearch } from "react-icons/fa"; import { useState } from "react"; import { SEARCH_TV } from "./data-fetch"; import SearchResults from "./searchResults"; const SearchBar = () => { const [title, setTitle] = useState(""); const [result, setResults] = useState(null); const [loading, setloading] = useState(false); const fetch_results = async (title) => { setloading(true); setResults(await SearchResults(await SEARCH_TV(title))); setloading(false); }; return (
setTitle(event.target.value)} onKeyDown={async (e) => { if ((e.key === "Enter" || e.code === 13) && title) { await fetch_results(e.target.value); } }} >
{loading && (

Please wait while we crunch up all the data

)}
{result}
); }; export default SearchBar;