[英]React + Typescript object props to component error
Simple case; 简单的情况; I'm rendering a list of 'Reviews'.
我正在呈现“评论”列表。 These are provided using the following Proptype:
使用以下属性类型提供这些:
export interface Props {
title: string;
name: string;
reviewdesc: string;
rating: number;
}
Mapping through the results in the parent component: 通过结果映射到父组件中:
{reviews.map((review: Props) => {
return <Review data={review} />;
})}
And using the same Proptypes in the child component: 并在子组件中使用相同的Proptypes:
const Review = (data: Props) => { ...
It is giving me this error: 它给了我这个错误:
Type '{ data: Props; }' is not assignable to type 'IntrinsicAttributes & Props'.
Property 'data' does not exist on type 'IntrinsicAttributes & Props'.
It feels like I'm forgetting a little thing. 感觉就像我忘了一件小事。 I thought I should catch the Props like
{data}
in the child component, but it gives: 我以为我应该在子组件中捕获
{data}
类的道具,但是它提供了:
Property 'data' does not exist on type 'Props'.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.