Vin*_*nny 8 typescript reactjs
我在尝试创建一个以“date”为键的多映射,然后遍历以数组作为值的多映射时遇到以下错误。
输入 '{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*/);
};
Run Code Online (Sandbox Code Playgroud)
Ale*_*yne 17
Task未输入为 receive children,但实际上您实际上是将换行文本节点作为任务的子节点传递。
<Task
key={index}
Index={counter.toString()}
Item={value}>{/* there is a new line text node here */}
</Task>
Run Code Online (Sandbox Code Playgroud)
你可能想让 JSX 标签自关闭以确保它没有子标签:
<Task
key={index}
Index={counter.toString()}
Item={value}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7991 次 |
| 最近记录: |