[英]Mixing strings and html links in react/typescript constants
Im trying to mix a string and a link, within an attribute of one variable:我试图在一个变量的属性中混合一个字符串和一个链接:
const News = [
{
headline: 'some headline',
text:
"some text" + <a href='url'> click me </a>,
},
];
Im displaying News on another page, when I access the text via news.text though I get following output我在另一个页面上显示新闻,当我通过news.text访问文本时,虽然我关注 output
some text[object Object]
Following code works fine以下代码工作正常
const News = [
{
headline: 'some headline',
text:
<a href='url'> click me </a>,
},
];
I have read similar questions, they were quite what I was looking for, since I feel like there has to be a simple solution for this small problem.我读过类似的问题,它们正是我想要的,因为我觉得必须有一个简单的解决方案来解决这个小问题。
if your las example works for you, maybe you could try something like this:如果你的 las 例子适合你,也许你可以尝试这样的事情:
const News = [
{
headline: 'some headline',
text: <span>Some text <a href='url'> click me </a></span>,
},
];
I haven't tested, but is just an idea.我没有测试,但只是一个想法。 Cheers!
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.