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.

Example of unstable JSX + parentheses

See original GitHub issue
function MyCompoent() {
  return (
    <div>
      (<FormattedMessage
        id="some-id"
        defaultMessage="some looooooooog default"
      />)
    </div>
  );
}

turns into:

function MyCompoent() {
  return (
    <div>
      (
      <FormattedMessage
        id="some-id"
        defaultMessage="some looooooooog default"
      />
      )
    </div>
  );
}

https://jlongster.github.io/prettier/#{"content"%3A"function MyCompoent() {\n return (\n <div>\n (<FormattedMessage\n id%3D\"some-id\"\n defaultMessage%3D\"some looooooooog default\"\n %2F>)\n <%2Fdiv>\n )%3B%5Cn%7D%5Cn%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22doc%22%3Afalse%7D%7D

which turns into:

function MyCompoent() {
  return (
    <div>
      (

      <FormattedMessage
        id="some-id"
        defaultMessage="some looooooooog default"
      />
      )
    </div>
  );
}

https://jlongster.github.io/prettier/#{"content"%3A"function MyCompoent() {\n return (\n <div>\n (\n <FormattedMessage\n id%3D\"some-id\"\n defaultMessage%3D\"some looooooooog default\"\n %2F>\n )\n <%2Fdiv>\n )%3B%5Cn%7D%5Cn%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22doc%22%3Afalse%7D%7D

It becomes stable after adding two newlines:

function MyCompoent() {
  return (
    <div>
      (


      <FormattedMessage
        id="some-id"
        defaultMessage="some looooooooog default"
      />
      )
    </div>
  );
}

https://jlongster.github.io/prettier/#{"content"%3A"function MyCompoent() {\n return (\n <div>\n (\n\n\n <FormattedMessage\n id%3D\"some-id\"\n defaultMessage%3D\"some looooooooog default\"\n %2F>\n )\n <%2Fdiv>\n )%3B%5Cn%7D%5Cn%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22doc%22%3Afalse%7D%7D

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
vjeuxcommented, Feb 14, 2017

The fact that it breaks is expected and I don’t think that we should put a hack for it. However the new line is not.

2reactions
rattrayalexcommented, Feb 14, 2017

Ah, no, that was silly of me. Of course it will break there. A bit unfortunate but very unlikely to be fixable without an ugly hack.

The insertion of an extra newline is a problem, I have some ideas about what might be causing that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

putting parentheses inside jsx breaks syntax : WEB-46905
Using React JSX, create a curly brace expression that returns a div with parentheses: const Test = () => ( <div> {<div>()</div>} </div>...
Read more >
When should I use curly braces { } and parenthesis ( ) in React?
Curly braces { } are special syntax in JSX. It is used to evaluate a JavaScript expression during compilation. A JavaScript expression can...
Read more >
All the JavaScript you need to know before starting with React
This is NOT a JavaScript template literal. These curly brackets in React are how you can insert dynamic expressions in JSX. You don't...
Read more >
JavaScript in JSX with Curly Braces - YouTube
When we want to add dynamic content to our HTML-like markup inside a JavaScript file we use curly braces. It's like our window...
Read more >
React conditional rendering: 9 methods with examples
Learn how to do conditional rendering in React. ... expressions can contain JSX, which you can wrap in parentheses to improve readability.
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