JSX - Ternary condition which renders a single JSXElement enforces useless braces
See original GitHub issuePrettier 1.10.2 Playground link
--print-width 100
--trailing-comma all
Input:
const cellComponent = props => props.column.name === 'actions'
? <Table.Cell {...props} value={<Actions {...props} />} />
: <Table.Cell {...props} />
Output:
const cellComponent = props =>
props.column.name === "actions" ? (
<Table.Cell {...props} value={<Actions {...props} />} />
) : (
<Table.Cell {...props} />
);
Expected behavior:
const cellComponent = props => props.column.name === 'actions'
? <Table.Cell {...props} value={<Actions {...props} />} />
: <Table.Cell {...props} />
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
React conditional rendering: 9 methods with examples
The ternary operator in React The operator is wrapped in curly braces, and the expressions can contain JSX, which you can wrap in...
Read more >How to use ternary operator within the jsx of a react ...
Place your condition in curly braces since your using JSX, the inside curcly braces, think of you have 3 parameters in your ternary...
Read more >eslint-plugin-react | Yarn - Package Manager
List of supported rules ; jsx-curly-spacing, Enforce or disallow spaces inside of curly braces in JSX attributes and expressions ; jsx-equals-spacing, Enforce or ......
Read more >React Design Patterns and Best Practices
Chapter 8, Server-Side Rendering for Fun and Profit, instructs that one of ... Alternatively, and better, we can use a ternary condition, which...
Read more >Joshua's Docs - React / JSX - Cheatsheet
Binding template literal to property expecting string: You have to use double brackets to "break out" of JSX and into regular JS.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t think there’s an eslint rule that will undo the formatting in the way you want.
There’s
prettier-eslint
, a tool that runs your code through an ESLint config of your choice after running Prettier, enabling you to choose and enforce your own style guide while still taking advantage of Prettier’s features.