Skip to content

Instantly share code, notes, and snippets.

@jackyef
Last active July 14, 2018 16:10
Show Gist options
  • Save jackyef/d7860144830c4c079d19c35a0c0af07d to your computer and use it in GitHub Desktop.
Save jackyef/d7860144830c4c079d19c35a0c0af07d to your computer and use it in GitHub Desktop.
renderContent = ({ data, error, loading, errorMessage }) => { // mengambil data, error, loading, errorMessage dari state milik Fetch
const { id } = this.props;
if (error) {
return <p>an error happened while trying to fetch comic #{id}</p>;
}
if (loading) {
return <p>loading...</p>;
}
if (data) {
const { alt, img, title } = data;
return (
<Fragment>
<h3>{title}</h3>
<figure>
<a href={img} target="_blank" rel="noreferrer nofollow noopener"><img src={img} /></a>
<figcaption>{alt}</figcaption>
</figure>
</Fragment>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment