General JSX Improvements
See original GitHub issueRemaining
- 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=""" />;
- 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:
- Created 7 years ago
- Reactions:8
- Comments:59 (26 by maintainers)
Top 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 >
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
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
Need to make each attribute on its own line when they overflow
should be
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}}
single quote settings should not affect jsx attributes. I’ve never seen anyone write
<div className='a' />
should remain
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}}