Skip to content

Commit f95129a

Browse files
committed
Added useEffect
1 parent 20475e2 commit f95129a

File tree

1 file changed

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

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState, useCallback } from 'react';
22

33
import MoviesList from './components/MoviesList';
44
import './App.css';
@@ -23,7 +23,7 @@ function App() {
2323
const [isLoading, setIsLoading] = useState(false)
2424
const [error, setError] = useState(null)
2525

26-
async function fetchMoviesHandler() {
26+
const fetchMoviesHandler = useCallback(async () => {
2727
setIsLoading(true)
2828
setError(null)
2929
try {
@@ -49,7 +49,11 @@ function App() {
4949
setError(error.message)
5050
}
5151
setIsLoading(false)
52-
}
52+
},[])
53+
54+
useEffect(()=> {
55+
fetchMoviesHandler()
56+
},[fetchMoviesHandler])
5357

5458
return (
5559
<React.Fragment>

0 commit comments

Comments
 (0)