File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Sections/Section 14/01-starting-project/src Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 1
- import React , { useState } from 'react' ;
1
+ import React , { useEffect , useState , useCallback } from 'react' ;
2
2
3
3
import MoviesList from './components/MoviesList' ;
4
4
import './App.css' ;
@@ -23,7 +23,7 @@ function App() {
23
23
const [ isLoading , setIsLoading ] = useState ( false )
24
24
const [ error , setError ] = useState ( null )
25
25
26
- async function fetchMoviesHandler ( ) {
26
+ const fetchMoviesHandler = useCallback ( async ( ) => {
27
27
setIsLoading ( true )
28
28
setError ( null )
29
29
try {
@@ -49,7 +49,11 @@ function App() {
49
49
setError ( error . message )
50
50
}
51
51
setIsLoading ( false )
52
- }
52
+ } , [ ] )
53
+
54
+ useEffect ( ( ) => {
55
+ fetchMoviesHandler ( )
56
+ } , [ fetchMoviesHandler ] )
53
57
54
58
return (
55
59
< React . Fragment >
You can’t perform that action at this time.
0 commit comments