File tree Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Expand file tree Collapse file tree 1 file changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -6,31 +6,29 @@ import "./styles.css";
6
6
import fetchData from "../../services/api" ;
7
7
8
8
export const useApi = url => {
9
- // TODO: loading, error, data loader from API
10
- // TODO: pass the url in so that we call fetchData(url)
11
- return {
12
- loading,
13
- error,
14
- data
15
- } ;
16
- } ;
17
-
18
- export const Feed = ( ) => {
19
9
const [ loading , setLoading ] = React . useState ( true ) ;
20
10
const [ error , setError ] = React . useState ( null ) ;
21
11
const [ data , setData ] = React . useState ( null ) ;
22
12
23
13
React . useEffect ( ( ) => {
24
- fetchData ( "messages" )
14
+ fetchData ( url )
25
15
. then ( result => {
26
16
setData ( result ) ;
27
17
setLoading ( false ) ;
28
18
} )
29
19
. catch ( error => {
30
20
setError ( error ) ;
31
21
} ) ;
32
- } , [ ] ) ;
22
+ } , [ url ] ) ;
23
+ return {
24
+ loading,
25
+ error,
26
+ data
27
+ } ;
28
+ } ;
33
29
30
+ export const Feed = ( ) => {
31
+ const { loading, error, data } = useApi ( "messages" ) ;
34
32
if ( loading ) {
35
33
return (
36
34
< div className = "Feed" >
You can’t perform that action at this time.
0 commit comments