This repository has been archived on 2025-10-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Cinemateket/src/App.tsx

40 lines
915 B
TypeScript
Raw Normal View History

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