Last active
August 12, 2018 04:50
-
-
Save s4kh/29d2ce1961d018ae8cd572e53d4b385a to your computer and use it in GitHub Desktop.
React design patterns example
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
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 => ( | |
<div className="img-container"> | |
<img src={img.url} alt={img.alt} /> | |
{img.description} - {img.author} | |
</div> | |
)) | |
: | |
<Loading /> | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment