Skip to content

Instantly share code, notes, and snippets.

@singhArmani
Last active April 7, 2019 07:35
Show Gist options
  • Save singhArmani/24e528ee292de600c0c776053cf6907a to your computer and use it in GitHub Desktop.
Save singhArmani/24e528ee292de600c0c776053cf6907a to your computer and use it in GitHub Desktop.
// Inside parent component
state = {
isLoading: true,
posts: [],
isErrorLoading: false,
error: null
};
// rendering logic handles by Parent Component (if statements)
// but the actual rendering job is handled by nested components
render() {
// LoadingComponent is resuable and can be used anywhere in the application
if (this.state.isLoading) {
return <LoadingComponent />;
}
if (this.state.isErrorLoading) {
return <ErrorLoadingComponent error={this.state.error} />;
}
return (
<div>
{/* some component */}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment