-
Notifications
You must be signed in to change notification settings - Fork 26.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistent quote style for both JS and JSX? #629
Comments
The "easier to type" thing I don't really buy because one shouldn't be using straight quotes from a typography standpoint - ie, 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. |
Agreed. The stated rationale is pretty weak.
Is this just aesthetics or do you see other reasons why double quotes are ideal in HTML?
Since JSX is a layer of syntactic sugar on top of JS, they seem pretty similar to me--at least in terms of what they do and how they operate. I think the value in having consistency between them in the areas they overlap is that when writing code, developers won't have to think about which style they should be using. This is particularly pronounced when you have JS that takes string arguments in your JSX props next to other string props. <MyComponent
someText="Hello"
somethingElse={this.makeSomething('good')}
/> It's not a huge deal, but I think that these microdecisions add up, and if it is easy to minimize them, then we should.
Perhaps, but what would this value be? |
Different rules apply. JS expressions can have side effects, JSX inline strings can't. (This is a weak argument in favor of the difference, but I'm just pointing it out). 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. |
well, if you write HTML in the XHTML style, you'd never not close a non-self-closing tag :-p |
Oh no, that was just a typo. The real catch is that you use "className" and not "class". |
Was also discussed here #269 (comment) |
Closing due to the discussion in that PR. |
The style guide says to prefer single quotes for JS. However, for JSX, it prefers double quotes because:
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?
The text was updated successfully, but these errors were encountered: