import axios from 'axios'; import { useState } from 'react'; import { ThreeDots } from 'react-loader-spinner'; import useSWR, { Fetcher } from 'swr'; import RateMovie from '../components/RateMovie'; import TMDBMovie from '../types/TMDBMovie'; const fetcher: Fetcher = async (url) => { const res = await axios.get(url, { headers: { Authorization: `Bearer ${import.meta.env.VITE_TMDB_BEARER_TOKEN}`, }, }); return res.data.results as TMDBMovie[]; }; function Rate() { const [value, setValue] = useState(''); const tmdbQuery = value ? `https://api.themoviedb.org/3/search/movie?query=${value}` : `https://api.themoviedb.org/3/trending/movie/day`; const { data, isLoading } = useSWR(tmdbQuery, fetcher); return (

Rate a movie

setValue(e.target.value)} className="mt-12 bg-gray-700 rounded-full py-2 px-4 mb-12 w-full" />
{isLoading && } {!isLoading && !data?.length &&

Could not find a movie 😬

} {!isLoading && !!data?.length && (
{data.slice(0, 12).map((movie) => ( ))}
)}
); } export default Rate;