Last active
January 13, 2021 14:12
-
-
Save mariocsantos/6571603799ab1c0c177b68d4ac78c1fa to your computer and use it in GitHub Desktop.
Dynamically favorite foods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react'; | |
import { getFavoritesFood } from './api'; | |
function FavoriteFoodList() { | |
const [list, setList] = useState([]); | |
const getList = async () => { | |
const newList = await getFavoritesFood(); | |
setList(newList); | |
}; | |
useEffect(() => { | |
getList(); | |
}, []); | |
return ( | |
<ul> | |
{list.map(item => <li key={item}>{item}</li>)} | |
</ul> | |
); | |
} | |
export { FavoriteFoodList }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment