Skip to content

Instantly share code, notes, and snippets.

@luizchaves97
Last active February 15, 2021 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizchaves97/927aa7cb70e98c159213d522c9dc2ea2 to your computer and use it in GitHub Desktop.
Save luizchaves97/927aa7cb70e98c159213d522c9dc2ea2 to your computer and use it in GitHub Desktop.
1 ano trabalhando com React
const MyComponent = () => {
const [photos, setPhotos] = useState([{url: 'initial.png', alt: 'Initial Photo'}]);
useEffect(() => {
const getPhotos = async () => {
return api.get('/photos');
}
const response = await getPhotos();
if (response) {
setPhotos((prevPhotos) => [...prevPhotos, response.data]);
}
}, []);
return (
<div>
{photos.forEach((photo) => (
<img src={photo.url} alt={photo.alt}>
))}
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment