This repository has been archived on 2024-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
Cinemateket/src/App.tsx

38 lines
864 B
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react'
2023-08-28 15:40:33 +02:00
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
function App() {
const API_MOVIE_KEY = import.meta.env.VITE_MOVIE_API_KEY;
const [movie, setMovie] = useState(null)
const [loading, setLoading] = useState(true)
useEffect(() => {
fetch(`http://www.omdbapi.com/?apikey=${API_MOVIE_KEY}&t=batman`)
.then((response) => response.json())
.then((data) => {
setMovie(data)
}
)
.then(() => setLoading(false))
.catch((error) => console.log(error))
}, [])
2023-08-28 15:40:33 +02:00
return (
<>
<div>
{!loading && movie ? (
<div>
<h1>{movie.Title}</h1>
<img src={movie.Poster} alt={movie.Title} />
</div>
):(<h1>Loading...</h1>)}
2023-08-28 15:40:33 +02:00
</div>
</>
)
}
export default App