Last active
February 15, 2021 19:44
-
-
Save luizchaves97/927aa7cb70e98c159213d522c9dc2ea2 to your computer and use it in GitHub Desktop.
1 ano trabalhando com React
This file contains hidden or 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
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