You may use quotes to specify string literals as attributes:
你可以使用引號指定字符串作為屬性:
const element = <div tabIndex="0"></div>;
You may also use curly braces to embed a JavaScript expression in an attribute:
你同樣可以在一個屬性里使用花括號嵌入一段JavaScript語法:
const element = <img src={user.avatarUrl}></img>
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.
千萬別在屬性上使用引號去包裹一個嵌入了JavaScript表達式的花括號宣决。這樣做JSX會把屬性當(dāng)作字符串而不是一個表達式劳翰。你要么使用引號(字符串)或者使用花括號(表達式),都是不要在同一個屬性上同時使用他們。