将prop用作元素id的正确语法是什么,除了前缀之外。我必须将每个变量分配给一个变量并使用字符串文字,还是可以内联吗?
例如
<input id="first_{id}" type="text" value={firstName} />
<input id="last_{id}" type="text" value={lastName} />
在您的值之外使用${}
,在javascript中称为template literals
{`your-prefix-${yourValue}`}
我更喜欢这样的字符串插值语法
<input id={`first_${id}`} type="text" value={firstName} />