Skip to content

Commit c49afb4

Browse files
committed
Using async and await
1 parent 83802c8 commit c49afb4

File tree

1 file changed

+3
-5
lines changed
  • Sections/Section 14/01-starting-project/src

1 file changed

+3
-5
lines changed

Sections/Section 14/01-starting-project/src/App.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ function App() {
2121

2222
const [movies, setMovies] = useState([])
2323

24-
function fetchMoviesHandler() {
25-
fetch('https://swapi.py4e.com/api/films').then(response => {
26-
return response.json();
27-
}).then(data => {
24+
async function fetchMoviesHandler() {
25+
const response = await fetch('https://swapi.py4e.com/api/films')
26+
const data = await response.json();
2827
const transformedMovies = data.results.map(movieData => {
2928
return {
3029
id: movieData.episode_id,
@@ -34,7 +33,6 @@ function App() {
3433
}
3534
})
3635
setMovies(transformedMovies)
37-
})
3836
}
3937

4038
return (

0 commit comments

Comments
 (0)