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.

Consistent quote style for both JS and JSX?

See original GitHub issue

The 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:closed
  • Created 8 years ago
  • Reactions:8
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
ljharbcommented, Dec 21, 2015

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.

4reactions
AlicanCcommented, Dec 29, 2015

I understand the majority viewpoint that “JSX is not HTML, it’s sugar over JS”, but that’s just not how I see it 😃

When I saw JSX I was like “HTML in JS? Booyah!” until this exploded in my face:

return (
  <div class="someclass" />
);

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.

Read more comments on GitHub >

github_iconTop 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, &apos;...
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 >

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