Last active
September 20, 2023 17:04
-
-
Save SeanPlusPlus/f0978654479bc3f6247db8eb31cf11aa to your computer and use it in GitHub Desktop.
Interview Answer React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react' | |
import './App.css' | |
export default function App() { | |
const [movies, setMovies] = useState([]) | |
const api = 'https://simplejson.vercel.app/api/awOkOFOw' | |
const getData = () => { | |
fetch(api, { | |
headers: { | |
'Content-Type': 'application/json', | |
'Accept': 'application/json' | |
} | |
}) | |
.then(function(response) { | |
return response.json() | |
}) | |
.then(function(json) { | |
setMovies(json.movies) | |
}); | |
} | |
useEffect(() => { | |
getData() | |
}, []) | |
return ( | |
<main> | |
{movies.map((movie) => ( | |
<div key={movie.title} className="movie"> | |
<div className="title">{movie.title}</div> | |
<div>{movie.rating}</div> | |
<div>{movie.release}</div> | |
<div>{movie.genres.join(', ')}</div> | |
</div> | |
))} | |
</main> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment