JSX - Only inline single expressions when the parent element contains text
See original GitHub issueExtracted 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:
- Created 6 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top 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 >
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 should be able to spent a little time on it tomorrow. I’ll see what I can come up with!
@vjeux
path.getParentNode()
made this fix nice and easy 😀