bracedStatements
Disallow unnecessary JSX curly braces around literals and JSX elements.
✅ This rule is included in the jsx stylistic preset.
Curly braces are necessary in JSX to embed JavaScript expressions. However, when wrapping simple string literals or JSX elements in curly braces, they add unnecessary visual clutter without providing value. Prefer using the content directly when possible for improved readability.
Examples
Section titled “Examples”<div>{"Hello"}</div><Component>{<span>Text</span>}</Component><div>{<ChildComponent />}</div><div>Hello</div><Component><span>Text</span></Component><div><ChildComponent /></div>Note that curly braces are still necessary for expressions, variables, and more complex JavaScript:
<div>{variable}</div><div>{someFunction()}</div><div>{1 + 2}</div>Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase has a specific style guide that requires curly braces for consistency in certain contexts, you may choose not to enable this rule. However, most style guides prefer removing unnecessary braces for cleaner code.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Deno:
jsx-curly-braces
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.