Last active
April 7, 2019 07:35
-
-
Save singhArmani/24e528ee292de600c0c776053cf6907a to your computer and use it in GitHub Desktop.
This file contains 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
// 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