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 - Only inline single expressions when the parent element contains text

See original GitHub issue

Extracted from https://github.com/prettier/prettier/pull/1831

Currently we always inline JSX if the element just contains a single expression:

<div>{variable}</div>

Generally there seems to be a preference to format the above as:

<div>
  {variable}
</div>

But we still want to allow inlining expressions when the parent element contains text.

// The expression can stay inlined here
<div>
  First <span>{variable}</span>
</div>

I’d need some time to investigate the approach, as I don’t currently know how to pass information about a parent element (whether it contains text) down to the child elements.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
karlcommented, Jun 26, 2017

I should be able to spent a little time on it tomorrow. I’ll see what I can come up with!

0reactions
karlcommented, Jun 26, 2017

@vjeux path.getParentNode() made this fix nice and easy 😀

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSX expressions must have one parent element - Stack Overflow
You can only return one element from a react component. Wrap everything in your render with another <div> or with a react fragment...
Read more >
Why must JSX expressions have only ONE parent element?
This error exists because JSX expressions must have only one parent element, and somewhere in this project, two parents have been used.
Read more >
React, Part I: JSX Cheatsheet - Codecademy
Nested JSX elements ... In order for the code to compile, a JSX expression must have exactly one outermost element. In the below...
Read more >
What are inline conditional expressions in ReactJS
So, if the first condition becomes true, it only renders react component. Syntax: Developers need to embed expression with the curly braces.
Read more >
calc() - CSS: Cascading Style Sheets - MDN Web Docs
The calc() function takes a single expression as its parameter, ... for controlling text size, be sure that one of the values includes...
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