Skip to content

Instantly share code, notes, and snippets.

@mariocsantos
Last active January 13, 2021 14:12
Show Gist options
  • Save mariocsantos/6571603799ab1c0c177b68d4ac78c1fa to your computer and use it in GitHub Desktop.
Save mariocsantos/6571603799ab1c0c177b68d4ac78c1fa to your computer and use it in GitHub Desktop.
Dynamically favorite foods
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