Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Created May 17, 2020 04:48
Show Gist options
  • Save zzdjk6/358e4b526b5690376a0bcc43f52e783e to your computer and use it in GitHub Desktop.
Save zzdjk6/358e4b526b5690376a0bcc43f52e783e to your computer and use it in GitHub Desktop.
React Hooks #EarlyReturn
const MyComponent: React.FC = () => {
const { loading, error, data } = useData();
if (loading) {
return <Spinner />;
}
if (error) {
return <Alert>{error.message}</Alert>;
}
if (isEmpty(data)) {
return <div>Data is empty</div>;
}
return <DataDisplay data={data} />;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment