File tree Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -6,19 +6,20 @@ import "./styles.css";
6
6
import fetchData from "../../services/api" ;
7
7
8
8
export const Feed = ( ) => {
9
- const loading = true ;
10
- const error = null ;
11
- const data = null ;
9
+ const [ loading , setLoading ] = React . useState ( true ) ;
10
+ const [ error , setError ] = React . useState ( null ) ;
11
+ const [ data , setData ] = React . useState ( null ) ;
12
12
13
- // TODO: useEffect to load state from fetchData
14
- fetchData ( "messages" )
15
- . then ( messages => {
16
- data = messages ;
17
- loading = false ;
18
- } )
19
- . catch ( error => {
20
- error = error ;
21
- } ) ;
13
+ React . useEffect ( ( ) => {
14
+ fetchData ( "messages" )
15
+ . then ( result => {
16
+ setData ( result ) ;
17
+ setLoading ( false ) ;
18
+ } )
19
+ . catch ( error => {
20
+ setError ( error ) ;
21
+ } ) ;
22
+ } , [ ] ) ;
22
23
23
24
if ( loading ) {
24
25
return (
You can’t perform that action at this time.
0 commit comments