Skip to content

Commit ef96e59

Browse files
justingrantgaearon
authored andcommitted
Reminder: strip quotes from attributes with JS code (#8806)
* Reminder: strip quotes from attributes with JS code Web developers who are used to standards-compliant HTML and XML will, out of habit, put quotes around all attributes because the standards require them. Other templating systems like ASP.NET also require (or at least allow) quotes around attributes that contain code. This behavior will get users into trouble in JSX because a quoted attribute is always treated as a string literal, even if it contains curly-braced javascript code. Let's add to the docs to help newbies evade this problem. * Tweak wording (cherry picked from commit fc30249)
1 parent d8700e8 commit ef96e59

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/docs/introducing-jsx.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ You may also use curly braces to embed a JavaScript expression in an attribute:
7979
const element = <img src={user.avatarUrl}></img>;
8080
```
8181

82+
Don't put quotes around curly braces when embedding a JavaScript expression in an attribute. Otherwise JSX will treat the attribute as a string literal rather than an expression. You should either use quotes (for string values) or curly braces (for expressions), but not both in the same attribute.
83+
8284
### Specifying Children with JSX
8385

8486
If a tag is empty, you may close it immediately with `/>`, like XML:

0 commit comments

Comments
 (0)