React w/Typescript:<Link>作为 prop 的一部分传递给子组件



我正试图将一个道具传递给一个子组件,其中该道具包括一个<Link>。以下是相关代码:

标签.tsx

export default function Label(props: LabelProps) {
return (
<label className={props.addClass} htmlFor={props.label}>
{props.title}
</label>
);
}

标签.ts

export interface LabelProps {
label: string,
title: string,
addClass?: string
}

Singup.tsx

<Label label='acceptTerms' title={`I accept the ${<Link to='./terms'></Link>}`} />

以下输出为:

我接受[目标对象]

title属性需要使用什么Typescript类型才能正确呈现?

使用类型React.ReactNode(而不是string(。

当通过一个";复数";内容:

<Label
label='acceptTerms'
title={(
<>
I accept the <Link to='./terms'></Link>}
</>
)}
/>

相关内容

最新更新