Skip to content

Instantly share code, notes, and snippets.

@tfiechowski
Created January 7, 2021 21:15
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 tfiechowski/9692d6196d9f3f9ea64ac1e8d3edd0c6 to your computer and use it in GitHub Desktop.
Save tfiechowski/9692d6196d9f3f9ea64ac1e8d3edd0c6 to your computer and use it in GitHub Desktop.
export function PhotosList() {
const onUpdate = useCallback(() => {
return new Promise((resolve) =>
setTimeout(resolve, getRandomBetween(1500, 2000))
);
}, []);
const { photos, updatePhotos } = usePhotos({
photos: DEFAULT_PHOTOS,
onUpdate,
});
function handleLike(photoId) {
updatePhotos([{ id: photoId, liked: true }]);
}
function handleUnlike(photoId) {
updatePhotos([{ id: photoId, liked: false }]);
}
return (
<PhotoGrid>
{photos.map((photo) => (
<PhotoWrapper key={photo.id}>
<Photo src={photo.src}></Photo>
{photo.locked ? (
<UpdatingButton />
) : photo.liked ? (
<UnlikeButton onUnlike={() => handleUnlike(photo.id)} />
) : (
<LikeButton onLike={() => handleLike(photo.id)}>Like</LikeButton>
)}
</PhotoWrapper>
))}
</PhotoGrid>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment