Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Created May 17, 2020 04:45
Show Gist options
  • Save zzdjk6/7b1da77699dd782319f2c724c7083500 to your computer and use it in GitHub Desktop.
Save zzdjk6/7b1da77699dd782319f2c724c7083500 to your computer and use it in GitHub Desktop.
React Component #EarlyReturn
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