Created
May 17, 2020 04:45
-
-
Save zzdjk6/7b1da77699dd782319f2c724c7083500 to your computer and use it in GitHub Desktop.
React Component #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
type Props = { | |
loading: boolean; | |
error?: Error; | |
data: Data; | |
}; | |
const MyComponent: React.FC<Props> = (props) => { | |
if (props.loading) { | |
return <Spinner />; | |
} | |
if (props.error) { | |
return <Alert>{props.error.message}</Alert>; | |
} | |
if (isEmpty(props.data)) { | |
return <div>Data is empty</div>; | |
} | |
return <DataDisplay data={props.data} />; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment