Access props inside quotes in React JSX

后端 未结 9 1201
广开言路
广开言路 2020-12-04 06:11

In JSX, how do you reference a value from props from inside a quoted attribute value?

For example:



        
9条回答
  •  [愿得一人]
    2020-12-04 06:40

    Instead of adding variables and strings, you can use the ES6 template strings! Here is an example:

    
    

    As for all other JavaScript components inside JSX, use template strings inside of curly braces. To "inject" a variable use a dollar sign followed by curly braces containing the variable you would like to inject. For example:

    {`string ${variable} another string`}
    

提交回复
热议问题