admin管理员组文章数量:1431317
I can pass something like this fine:
<CardTitle title={this.props.post.title} subtitle={
<Link to={this.props.post.author}>{this.props.post.author}</Link>
} />
But I need to pass both a ponent and some string text, but doing this doesn't work:
<CardTitle title={this.props.post.title} subtitle={(`
This is a link: ${<Link to={this.props.post.author}>{this.props.post.author}</Link>}
`)} />
What's the right syntax for this?
I can pass something like this fine:
<CardTitle title={this.props.post.title} subtitle={
<Link to={this.props.post.author}>{this.props.post.author}</Link>
} />
But I need to pass both a ponent and some string text, but doing this doesn't work:
<CardTitle title={this.props.post.title} subtitle={(`
This is a link: ${<Link to={this.props.post.author}>{this.props.post.author}</Link>}
`)} />
What's the right syntax for this?
Share Improve this question asked Mar 17, 2018 at 22:52 user967451user9674511 Answer
Reset to default 6Try passing it as a React Element altogether, not as a string:
<CardTitle
title={this.props.post.title}
subtitle={
<span>
This is a link: <Link to={this.props.post.author}>{this.props.post.author}</Link>
</span>
}
/>
Then should be able to render subtitle
as is. If you're using React >16, you might want to use Fragments for this:
import { Fragment } from 'react';
// ...
subtitle={
<Fragment>
This is a link: <Link to={this.props.post.author}>{this.props.post.author}</Link>
</Fragment>
}
本文标签: javascriptHow to pass string and component as propStack Overflow
版权声明:本文标题:javascript - How to pass string and component as prop? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745570692a2664029.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论