admin管理员组文章数量:1294325
I am trying to use variable in curly braces in anchor tag's href string.
suppose value of {entry.email} is [email protected] then I am trying to do this<a href="mailto:"+{entry.email}>{entry.email}</a>
to generate anchor tag
<a href="mailto:abc@xyz">abc@xyz
in following code
const rows = props.contacts.map((entry, index) => {
return (
<tr key={index}>
<td><a href="mailto:"+{entry.email}>{entry.email}</a></td>
</tr>
);
But clearly this is not working or even piling. How do I do this?
I am trying to use variable in curly braces in anchor tag's href string.
suppose value of {entry.email} is [email protected] then I am trying to do this<a href="mailto:"+{entry.email}>{entry.email}</a>
to generate anchor tag
<a href="mailto:abc@xyz">abc@xyz
in following code
const rows = props.contacts.map((entry, index) => {
return (
<tr key={index}>
<td><a href="mailto:"+{entry.email}>{entry.email}</a></td>
</tr>
);
But clearly this is not working or even piling. How do I do this?
Share edited Nov 3, 2021 at 11:20 Giorgi Moniava 28.7k9 gold badges57 silver badges98 bronze badges asked Nov 2, 2019 at 19:10 Saurabh kukadeSaurabh kukade 1,6362 gold badges13 silver badges25 bronze badges3 Answers
Reset to default 9Try with template literals
href={`mailto: ${entry.email}`} // or {`mailto: ${entry.email || ""}`} to avoid null or undefined being stringified
or
href={"mailto: "+ entry.email} // or {"mailto: " + (entry.email || "")} to avoid null or undefined being stringified
You can use this:
<a href={`mailto:${entry.email}`}>
String concatenation whether using quote marks or string literals will work as long as they are declared inside curly braces...
OPTION ONE:
<a href={"mailto: "+ entry.email}>
OPTION TWO:
<a href={`mailto: ${entry.email}`}>
本文标签: javascriptHow to concatenate variable to href tag in react jsStack Overflow
版权声明:本文标题:javascript - How to concatenate {variable} to href tag in react js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741597284a2387486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论