Skip to content

Commit fef336f

Browse files
committed
Clarify conditional rendering: expressions vs statements
Explain that JSX braces expect expressions, not statements, and show how to use if before return vs expression forms inline. Fixes #8247
1 parent dffae74 commit fef336f

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` goes in regular JavaScript *before* the returned JSX, while the result of that `if` (like `content`) is placed inside `{ }`. When you need to branch inline, 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)