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";
66import fetchData from "../../services/api" ;
77
88export 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 ) ;
1212
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+ } , [ ] ) ;
2223
2324 if ( loading ) {
2425 return (
You can’t perform that action at this time.
0 commit comments