Skip to content

Conversation

@kanikaa88
Copy link

Summary

Clarifies a potentially misleading explanation on /learn about conditionals in JSX.

JSX curly braces ({}) accept expressions, not statements. This can confuse beginners into thinking if "doesn't work in JSX", when the real issue is that if is a statement and must be used in regular JavaScript before returning JSX.

Fixes #8247

What changed

  • Updated src/content/learn/index.md in the Conditional rendering section.
  • Added a short note explaining:
    • {} in JSX expects an expression
    • if is a statement, so it should run before return (e.g. assign JSX to a variable)
    • for inline branching inside JSX, use an expression form like ? :

Verification

  • Checked /learn locally and confirmed the clarification reads naturally between the if...else example and the ? : example.

Explain that JSX curly braces expect expressions, not statements,
and show how to use if before return vs expression forms inline.
Fixes reactjs#8247
@github-actions
Copy link

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion]: Correction of misleading explanation in react.dev/learn (Quick Start)

1 participant