【发布时间】:2020-11-24 20:40:29
【问题描述】:
我在尝试创建一个以“日期”为键的多图时遇到以下错误,然后遍历以数组为值的多图。
输入 '{children: never[];键:字符串;索引:字符串;项目:SomeItem[]; }' 不可分配给类型 'IntrinsicAttributes & Props'。类型“IntrinsicAttributes & Props”上不存在属性“children”。 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*/);
};
【问题讨论】:
标签: reactjs typescript