Skip to content

Commit bce4156

Browse files
committed
Clarify that JSX braces require expressions
Explain that JSX curly braces expect expressions, not statements, and show how to use if before return vs expression forms inline. Fixes #8247
1 parent a1ddcf5 commit bce4156

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/content/learn/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ return (
197197
);
198198
```
199199
200+
JSX curly braces expect **expressions**, not statements. This is why `if` runs in regular JavaScript *before* the returned JSX, while the result of that `if` (like `content`) is placed inside `{ }`. When you need to branch inline inside JSX, use an expression form such as the conditional (`? :`) operator.
201+
200202
If you prefer more compact code, you can use the [conditional `?` operator.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) Unlike `if`, it works inside JSX:
201203
202204
```js

0 commit comments

Comments
 (0)