作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试创建一个以“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/
我是一名优秀的程序员,十分优秀!