Skip to content

Instantly share code, notes, and snippets.

@klemola
Last active May 16, 2019 10:34
Show Gist options
  • Save klemola/83840cfa571f89d87430ddb78e4245af to your computer and use it in GitHub Desktop.
Save klemola/83840cfa571f89d87430ddb78e4245af to your computer and use it in GitHub Desktop.
function render(
userRequest: RemoteData<User, Error>,
translationsRequest: RemoteData<Translations, Error>
) {
if (isLoading(userRequest) || isLoading(translationsRequest)) {
return "Loading...";
} else if (isSuccess(userRequest) && isSuccess(translationsRequest)) {
const { username } = userRequest.data;
const { greeting } = translationsRequest.data;
return `${greeting}, ${username}`;
} else if (isFailure(userRequest) || isFailure(translationsRequest)) {
return "Could not initialize the application!";
} else {
return null;
}
}
/* ...simulated fetch functions */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment