我可以得到一些关于IconArr.primary
属性接口定义的帮助吗.
我正在try 将其传递到PrimarySkills
个组件中-->;我必须定义接口,但到目前为止运气不好.
我不想用主图标和次图标传递整个对象,因此我可以有两个单独的组件,但稍后会有不同的输入数据.
const iconsArr = {
primary: [
{
id: '0',
imgPath: 'images/techIcons/reactjs.svg',
name: 'React',
},
{
id: '1',
imgPath: 'images/techIcons/nextjs.svg',
name: 'NextJS',
},
],
secondary: [
{
id: '0',
imgPath: 'images/techIcons/csharp.svg',
name: 'C#',
},
{
id: '1',
imgPath: 'images/techIcons/java.svg',
name: 'Java',
},
],
};
const Skills = (props: Props) => {
return (
<div>
<StyledCaption contentString='SKILLS'>PRIMARY</StyledCaption>
<PrimarySkills iconsArr={iconsArr.primary} />
</div>
);
};
in PrimarySkills
组件
interface Props {
iconsArr: {
primary: {
id: string;
imgPath: string;
name: string;
}[];
};
}
const PrimarySkills = (props: Props) => {
return (
<div>
{props.iconsArr.primary.map((icon) => (
<img src={icon.imgPath} alt={icon.name} key={icon.id} height='30' />
))}
</div>
);
};