简体   繁体   English

未捕获的错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数但得到:对象

[英]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.

相关问题 未捕获的错误:不变违规:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数但得到:object - Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object 未捕获的错误:元素类型无效:预期为字符串(内置组件)或类/函数(复合组件),但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (built-in components) or a class/function ( composite components) but got: undefined 未捕获的错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got:undefined 错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:ReactJS 中的对象 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object in ReactJS 错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:对象 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object × 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:object - × Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object 不变违规:元素类型无效:预期为字符串(内置组件)或类/函数(复合组件),但得到:对象 - Invariant Violation: Element type is invalid: expected a string (built-in components) or a class/function (composite components) but got: object 错误 - 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - error - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 渲染错误元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Render Error Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM