Skip to content

Instantly share code, notes, and snippets.

@nonsensery nonsensery/ArticleView.jsx Secret
Created Aug 3, 2015

Embed
What would you like to do?
Flawed async ArticleView.updateArticle()
// Can you spot the asynchonous operation in this code?
ArticleView.prototype.updateArticle = function (props) {
this.setState({ error: null, title: null, body: null });
try {
var article = await ArticleStore.fetch(props.articleID);
this.setState({ title: article.title, body: article.body });
} catch (err) {
this.setState({ error: 'Oh Noes!' });
});
};
@Semigradsky

This comment has been minimized.

Copy link

commented Sep 5, 2015

Correct code:

// Can you spot the asynchonous operation in this code?

ArticleView.prototype.updateArticle = async function (props) {
  this.setState({ error: null, title: null, body: null });

  try {
    var article = await ArticleStore.fetch(props.articleID);
    this.setState({ title: article.title, body: article.body });
  } catch (err) {
    this.setState({ error: 'Oh Noes!' });
  };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.