我可以通过这样的罚款:
<CardTitle title={this.props.post.title} subtitle={
<Link to={this.props.post.author}>{this.props.post.author}</Link>
} />
但我需要传递一个组件和一些字符串文本,但这样做不起作用:
<CardTitle title={this.props.post.title} subtitle={(`
This is a link: ${<Link to={this.props.post.author}>{this.props.post.author}</Link>}
`)} />
正确的语法是什么?
尝试将其完全作为 React 元素传递,而不是作为字符串传递:
<CardTitle
title={this.props.post.title}
subtitle={
<span>
This is a link: <Link to={this.props.post.author}>{this.props.post.author}</Link>
</span>
}
/>
然后应该能够渲染subtitle
照原样。如果你使用 React >16,你可能想使用碎片为了这:
import { Fragment } from 'react';
// ...
subtitle={
<Fragment>
This is a link: <Link to={this.props.post.author}>{this.props.post.author}</Link>
</Fragment>
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)