Skip to content

Instantly share code, notes, and snippets.

@s4kh
Created August 12, 2018 05:02
Show Gist options
  • Save s4kh/38e417fbdff14270412f4624a1509c4c to your computer and use it in GitHub Desktop.
Save s4kh/38e417fbdff14270412f4624a1509c4c to your computer and use it in GitHub Desktop.
const GalleryItem = ({ url, alt, description, alt, author }) => (
<div className="img-container">
<img src={url} alt={alt} />
{description} - {author}
</div>
);
class Gallery extends Component {
state = {
isLoading: false,
currentImage: 0,
imgs: [],
};
componentDidMount() {
this.setState({ isLoading: true });
// AJAX API call here
getImgs(API_URL).then(data => {
this.setState(() => ({ imgs: data.imgs, isLoading: false }))
});
}
render() {
const { imgs, isLoading } = this.state;
return (
{!isLoading ? imgs.map(img => (
<GalleryItem {...img} />
))
:
<Loading />
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment