✨ showing list of movie items
Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
		
							parent
							
								
									b13bfa965c
								
							
						
					
					
						commit
						a65ac11429
					
				
					 2 changed files with 22 additions and 14 deletions
				
			
		
							
								
								
									
										6
									
								
								.prettierrc.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.prettierrc.json
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | ||||||
|  | { | ||||||
|  |     "trailingComma": "es5", | ||||||
|  |     "tabWidth": 2, | ||||||
|  |     "semi": false, | ||||||
|  |     "singleQuote": true | ||||||
|  | } | ||||||
							
								
								
									
										24
									
								
								src/App.tsx
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								src/App.tsx
									
										
									
									
									
								
							|  | @ -1,21 +1,17 @@ | ||||||
| import { useEffect, useState } from 'react' | import { useEffect, useState } from 'react' | ||||||
| import reactLogo from './assets/react.svg' |  | ||||||
| import viteLogo from '/vite.svg' |  | ||||||
| import './App.css' | import './App.css' | ||||||
| 
 | 
 | ||||||
| function App() { | function App() { | ||||||
| 
 |   const API_MOVIE_KEY = import.meta.env.VITE_MOVIE_API_KEY | ||||||
|   const API_MOVIE_KEY = import.meta.env.VITE_MOVIE_API_KEY; |   const [movies, setMovies] = useState([]) | ||||||
|   const [movie, setMovie] = useState(null) |  | ||||||
|   const [loading, setLoading] = useState(true) |   const [loading, setLoading] = useState(true) | ||||||
| 
 | 
 | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     fetch(`http://www.omdbapi.com/?apikey=${API_MOVIE_KEY}&t=batman`) |     fetch(`http://www.omdbapi.com/?apikey=${API_MOVIE_KEY}&s=batman`) | ||||||
|       .then((response) => response.json()) |       .then((response) => response.json()) | ||||||
|       .then((data) => { |       .then((data) => { | ||||||
|         setMovie(data) |         setMovies(data.Search) | ||||||
|       } |       }) | ||||||
|       ) |  | ||||||
|       .then(() => setLoading(false)) |       .then(() => setLoading(false)) | ||||||
|       .catch((error) => console.log(error)) |       .catch((error) => console.log(error)) | ||||||
|   }, []) |   }, []) | ||||||
|  | @ -23,12 +19,18 @@ function App() { | ||||||
|   return ( |   return ( | ||||||
|     <> |     <> | ||||||
|       <div> |       <div> | ||||||
|         {!loading && movie ? ( |         {!loading && movies ? ( | ||||||
|  |           <div> | ||||||
|  |             {movies.map((movie: any) => ( | ||||||
|               <div> |               <div> | ||||||
|                 <h1>{movie.Title}</h1> |                 <h1>{movie.Title}</h1> | ||||||
|                 <img src={movie.Poster} alt={movie.Title} /> |                 <img src={movie.Poster} alt={movie.Title} /> | ||||||
|               </div> |               </div> | ||||||
|         ):(<h1>Loading...</h1>)} |             ))} | ||||||
|  |           </div> | ||||||
|  |         ) : ( | ||||||
|  |           <h1>Loading...</h1> | ||||||
|  |         )} | ||||||
|       </div> |       </div> | ||||||
|     </> |     </> | ||||||
|   ) |   ) | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 haraldnilsen
						haraldnilsen