Skip to content

Instantly share code, notes, and snippets.

@SeanPlusPlus
Last active September 20, 2023 17:04
Show Gist options
  • Save SeanPlusPlus/f0978654479bc3f6247db8eb31cf11aa to your computer and use it in GitHub Desktop.
Save SeanPlusPlus/f0978654479bc3f6247db8eb31cf11aa to your computer and use it in GitHub Desktop.
Interview Answer React
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