Consistent quote style for both JS and JSX?
See original GitHub issueThe style guide says to prefer single quotes for JS. However, for JSX, it prefers double quotes because:
double quotes make conjunctions like
"don't"
easier to type
Although in practice it probably occurs less frequently, you could make the same argument for using single quotes to make quoted bits like 'Say "hello"'
easier to type.
Still, all of this seems to me to matter less than the consistency that would be gained by choosing either single quotes or double quotes for both JS and JSX. What do you think?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:8 (3 by maintainers)
Top Results From Across the Web
jsx-quotes - ESLint - Pluggable JavaScript Linter
This rule enforces the consistent use of either double or single quotes in JSX attributes. Options. This rule has a string option: "prefer-double"...
Read more >React JSX, how to render text with a single quote? ...
Render as a JS string literal (with double-quotes): return (<p>{"I've seen the movie."}</p>) ... or use the HTML entity for an apostrophe, '...
Read more >Introducing JSX
It is called JSX, and it is a syntax extension to JavaScript. ... React separates concerns with loosely coupled units called “components” that...
Read more >“Double Quotes” vs 'Single Quotes' vs `Backticks` in ...
Although single quotes and double quotes are the most popular, we have a 3rd option called Backticks ( `` ). Backticks are an...
Read more >Breathing air into AirBnB's JavaScript Style Guide
Since JSX is closer to HTML, the tendency is to add attributes between double quotes. So I started using double quotes for everything,...
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 FreeTop 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
Top GitHub Comments
The “easier to type” thing I don’t really buy because one shouldn’t be using straight quotes from a typography standpoint - ie,
'don’t'
and"don’t"
are equally easy to type. We should improve the rationale in that section.Personally I prefer double quotes in JSX because double quotes are also ideal for HTML (even though single quotes work, they look ugly in HTML), and I see JSX and HTML as largely similar.
JS and JSX aren’t the same - I don’t see any value in necessarily having consistency between them. I also think that there’s value in differentiating inline JSX values from JS values.
When I saw JSX I was like “HTML in JS? Booyah!” until this exploded in my face:
I started using single quotes for JSX because it immediately sets my brain’s “This is not HTML, this is JSX.” mode on. HTML has no power here. It’s all about it’s JS API.
Edit: Fixed the typo mentioned in the following comments.