gpt4 book ai didi

reactjs - ts(2322) 类型 'Intrinsic attributes and Props' 上不存在属性子项

转载 作者:行者123 更新时间:2023-12-04 11:04:55 25 4
gpt4 key购买 nike

我在尝试创建一个以“date”为键的多映射,然后遍历以数组作为值的多映射时遇到以下错误。

Type '{children: never[]; key: string; Index: string; Item: SomeItem[]; }' is not assignable to type 'IntrinsicAttributes & Props'. Property 'children' does not exist on type 'IntrinsicAttributes & Props'. ts(2322)


并且不知道如何解决这个问题

const History = () => {


const [counter, setCounter] = useState(0);
type SomeMap = Map<string, SomeItem[]>;
let map: SomeMap = new Map();

//Items is of type SomeItem[]
Items.foreach((item) =>{
if(map.has(item.date)){
(map.get(item.date) ?? []).push(item);
}
else{
map.set(item.date,[item]);
}
});

return(
<Accordian>
{ map.foreach((value, index) => {
setCounter(counter +1 );
<Task
key={index}
Index={counter.toString()}
Item={value}>
</Task>
})}
</Accordian>
);

};



type Props = {
index: string;
Item: SomeItem[];
};

const Task = (props:Props) => {

const index = props.Index;
const Item = props.SomeItem;


render(/*Some Code*/);
};


最佳答案

Task未输入以接收 children ,但实际上您实际上是将换行文本节点作为任务的子节点传递。

      <Task
key={index}
Index={counter.toString()}
Item={value}>{/* there is a new line text node here */}
</Task>
你可能想让 JSX 标签自关闭以确保它没有子标签:
      <Task
key={index}
Index={counter.toString()}
Item={value}
/>
Playground

关于reactjs - ts(2322) 类型 'Intrinsic attributes and Props' 上不存在属性子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63252161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com