Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compound Conditions: "bad" example is a syntax error #39

Open
rcreasi opened this issue Mar 17, 2017 · 0 comments
Open

Compound Conditions: "bad" example is a syntax error #39

rcreasi opened this issue Mar 17, 2017 · 0 comments

Comments

@rcreasi
Copy link

rcreasi commented Mar 17, 2017

Under Compound Conditions the following example of bad style appears:

// bad
render () {
  return <div>{if (this.state.happy && this.state.knowsIt) { return "Clapping hands" }</div>;
}

This is not merely bad style; it's a syntax error. Firstly, the curly braces aren't balanced. Secondly, even if we balanced them, if (...) { return ... } is not an expression so it cannot be embedded in JSX.

The example should read

// bad
render () {
  return <div>{(this.state.happy && this.state.knowsIt) && "Clapping hands" }</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant