Created
May 17, 2020 04:48
-
-
Save zzdjk6/358e4b526b5690376a0bcc43f52e783e to your computer and use it in GitHub Desktop.
React Hooks #EarlyReturn
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
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