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

54 lines
1.2 KiB
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react'
2023-08-28 15:40:33 +02:00
import './App.css'
2023-09-04 11:12:35 +02:00
import q from 'qjuul'
2023-08-28 15:40:33 +02:00
function App() {
2023-09-04 11:12:35 +02:00
const API_MOVIE_KEY = 'd92949d8'
const [movies, setMovies] = useState([])
const [loading, setLoading] = useState(true)
useEffect(() => {
2023-09-04 11:12:35 +02:00
fetch(`http://www.omdbapi.com/?apikey=${API_MOVIE_KEY}&s=spider-man`)
.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 (
<>
2023-09-04 11:12:35 +02:00
<q.div>
<div>
<h1>All movies</h1>
</div>
{!loading && movies ? (
<div>
2023-09-04 11:12:35 +02:00
<table>
<tr>
<th>Poster</th>
<th>Title</th>
<th>Year</th>
</tr>
{movies.map((movie: any) => (
<tr>
<td>
<img src={movie.Poster} alt={movie.Title} width="100" />
</td>
<td>{movie.Title}</td>
<td>{movie.Year}</td>
</tr>
))}
</table>
</div>
) : (
<h1>Loading...</h1>
)}
2023-09-04 11:12:35 +02:00
</q.div>
2023-08-28 15:40:33 +02:00
</>
)
}
export default App