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.

General JSX Improvements

See original GitHub issue

Remaining

  • Expand last argument of arrow function
const els = items.map(item => (
  <div className="whatever">
    <span>{children}</span>
  </div>
));

Right now turns to

const els = items.map(
  item => (
    <div className="whatever">
      <span>{children}</span>
    </div>
  )
);
  • Wrong indent for arrow functions inside of {}
<Something>
  {() => (
      <SomethingElse>
        <span />
      </SomethingElse>
    )}
</Something>;
  • single arrays and objects should stay on the same line and not put on the next indent
<View
  style={
    [
      {
        someVeryLongStyle1: "true",
        someVeryLongStyle2: "true"
      }
    ]
  }
/>;

should be

<View
  style={[
    {
      someVeryLongStyle1: "true",
      someVeryLongStyle2: "true"
    }
  ]}
/>;

and

<View
  style={
    {
      someVeryLongStyle1: "true",
      someVeryLongStyle2: "true"
    }
  }
/>;

should be

<View
  style={{
    someVeryLongStyle1: "true",
    someVeryLongStyle2: "true"
  }}
/>;

Fixed

  • Put parenthesis for bracket-less arrow functions
const StatelessComponent = ({ children }) => (
  <div className="whatever">
    <span>{children}</span>
  </div>
);
  • Put parenthesis for return
function StatelessComponent({ children }) {
  return (
    <div className="whatever">
      <span>{children}</span>
    </div>
  );
}
  • Puts parenthesis for variable declaration
const comp4 = (
  <div style={styles} key="something">
    Create wrapping parens and indent <strong>all the things</strong>.
  </div>
);
  • Preserve space between text nodes and jsx elements in a single line
<span>
    foo <span>bar</span>
</span>
  • Properly escape quotes
<div id='"' />;

should turn into

<div id="&quot;" />;
  • Use double quotes for jsx attributes even with --single-quote
<div id="a" />
  • Should print names with . correctly
<route.page />;
  • brackets should be on the same line as the attributes
const MyComponent = (props) => 
    <div>{
        some.very.very.very.very.very.very.very.very.very.very.long.props.text
    }</div>

should be

const MyComponent = props => (
  <div>
    {some.very.very.very.very.very.very.very.very.very.very.long.props.text}
  </div>
);

(Note: the original issue has been replaced with this list of remaining items, so comments below might not make sense)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:59 (26 by maintainers)

github_iconTop GitHub Comments

7reactions
vjeuxcommented, Jan 11, 2017

Need to make each attribute on its own line when they overflow

<div a="1" b="2" c="3" d="4" e="5" f="6" g="7" h="8"/>

should be

<div
  a="1"
  b="2"
  c="3"
  d="4"
  e="5"
  f="6"
  g="7"
  h="8"
/>

https://vjeux.github.io/prettier-browser/#{"content"%3A"<div a%3D\"1\" b%3D\"2\" c%3D\"3\" d%3D\"4\" e%3D\"5\" f%3D\"6\" g%3D\"7\" h%3D\"8\"%2F>"%2C"options"%3A{"printWidth"%3A33%2C"tabWidth"%3A2%2C"singleQuote"%3Afalse%2C"trailingComma"%3Afalse%2C"bracketSpacing"%3Atrue}}

6reactions
vjeuxcommented, Jan 11, 2017

single quote settings should not affect jsx attributes. I’ve never seen anyone write <div className='a' />

<div id="a" />

should remain

<div id="a" />

even with singleQuote option enabled

https://vjeux.github.io/prettier-browser/#{"content"%3A"<div id%3D\"a\" %2F>"%2C"options"%3A{"printWidth"%3A34%2C"tabWidth"%3A2%2C"singleQuote"%3Atrue%2C"trailingComma"%3Afalse%2C"bracketSpacing"%3Atrue}}

Read more comments on GitHub >

github_iconTop Results From Across the Web

React v18.0 – React Blog
Our latest major version includes out-of-the-box improvements like automatic batching, new APIs like startTransition, and streaming ...
Read more >
React Best Practices – Tips for Writing Better React Code in ...
It's a general problem in programming. Not having a solid understanding of React can also cause issues for you as a developer. I...
Read more >
21 Performance Optimization Techniques for React Apps
Optimize your React application's performance with these 21 techniques. ... In general, mouse clicks have lower event trigger rates compare ...
Read more >
JSX is inefficient by default … but … | by Andrea Giammarchi
Please don't miss JSX can be more efficient by default post, ... too that don't really care about ECMAScript or the Web specs...
Read more >
React 18 - What Changes Does It Bring And How Will They ...
Nevertheless, this is a major improvement to the user experience: now your users will at least get some feedback; they will know something...
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 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