question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSX - Ternary condition which renders a single JSXElement enforces useless braces

See original GitHub issue

Prettier 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:closed
  • Created 6 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
suchipicommented, Feb 7, 2018

I don’t think there’s an eslint rule that will undo the formatting in the way you want.

1reaction
j-f1commented, Feb 7, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found