[英]Pass JSX within object to react child component?
I am trying to pass content to a component that includes link tags, but am getting [object Object]
instead of the link I am expecting.我正在尝试将内容传递给包含链接标签的组件,但得到的是[object Object]
而不是我期望的链接。 Is there a way to do this?有没有办法做到这一点?
parent component父组件
const data = {
title: city,
content: `click the link ${<a href="/example">here</a>} to continue`
}
return (
<RandomComponent data={data}
)}
child component子组件
return (
<div>
<p>{data.content}</P>
</div>
currently it is returning目前它正在返回
click the link [object Object] to continue
Make the content
a JSX element instead.将content
改为 JSX 元素。
const data = {
title: city,
content: <>click the link <a href="/example">here</a> to continue</>
}
and then接着
<p>{data.content}</p>
will insert it as desired.将根据需要插入它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.