Skip to content

Instantly share code, notes, and snippets.

@klemola
Last active May 16, 2019 10:34
Show Gist options
  • Save klemola/e474c2a6cebc26402a47b7299cac0425 to your computer and use it in GitHub Desktop.
Save klemola/e474c2a6cebc26402a47b7299cac0425 to your computer and use it in GitHub Desktop.
export function main() {
let userRequest: Data = { type: "Loading" };
fetchData()
.then(response => {
userRequest = { type: "Success", data: response };
})
.catch(error => {
userRequest = { type: "Failure", error };
});
}
function render(userRequest: Data) {
switch (userRequest.type) {
case "Loading":
return "Loading...";
case "Success":
return `Hello, ${userRequest.data.username}`;
case "Failure":
return "Could not fetch data!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment