[英]Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function but got: object
I'm trying to build my First reactjs site, protfolio project, Right now I'm at the skills section.我正在尝试构建我的第一个 reactjs 站点,protfolio 项目,现在我在技能部分。 I made a Skill file of an array of objects of my skills so that I could use map funtion in my Skills.jsx components and in fututre I could just add another skill object and map() will render it.
我制作了一个包含我的技能对象数组的技能文件,这样我就可以在我的 Skills.jsx 组件中使用地图功能,并且在未来我可以添加另一个技能对象,然后 map() 将渲染它。 Once done with the the array of objects my site was rendering but all of a sudden I got this error!!
一旦完成了我的网站正在渲染的对象数组,但突然间我得到了这个错误!!
//My Skills.jsx: Once I render this I will use props for the map function.
import React from "react";
function Skills() {
return (
<>
<section className="skills">
<div className="card">
<div className="content">
<img src="./src/assets/html5.svg" alt="htmlIcon" />
<p>HTML</p>
</div>
</div>
</section>
</>
);
}
export default Skills;
//My Skills JSON: (I have 10 objects in it.)
const skills = [
{
id: 1,
icon: "./src/assets/html5.svg",
iconName: "HTML",
},
];
export default skills;
I want to render the Skill JSON obect in my Skills.jsx component using map function!!我想使用映射函数在我的 Skills.jsx 组件中呈现技能 JSON 对象!
Figured out the Map function, and I have successfully implemented it now all that is left is styling it!!弄清楚了 Map 函数,我已经成功地实现了它,现在剩下的就是设计它了!!
//Skills.jsx:
import React from "react";
function Skills(props) {
return (
<>
<section className="skills">
<div className="card">
Skills
<div className="content">
<img src={props.icon} alt="htmlIcon" />
<p>{props.iconName}</p>
</div>
</div>
</section>
</>
);
}
export default Skills;
//App.jsx:
import React from "react";
import Skills from "./Skills";
import skills from "./Skill";
import Footer from "./Footer";
function addSkill(skill) {
return (
<Skills
key={skill.id}
id={skill.id}
icon={skill.icon}
iconName={skill.iconName}
/>
);
}
function App(){
return(
<>
{skills.map(addSkill)}
</>
);
}
export default App;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.