简体   繁体   English

尝试渲染反应组件时,未定义“名称框”反应/jsx-no-undef 错误

[英]Getting 'Namebox' is not defined react/jsx-no-undef error when trying to render a react Component

I'm learning react and I'm stuck on this issue.我正在学习反应并且我被困在这个问题上。 All I want to do is to render a component which resides in the current Class.我想要做的就是渲染一个驻留在当前类中的组件。 When I run this code I'm getting an error .当我运行此代码时,出现错误。

This is the Code.这是守则。

class NamesBox extends React.Component{

    constructor(){
        super();
    }

    Namebox(props){
        return(
          <div>
             <div>{props.name}</div>
           </div>
        );
    }

    sayHello() {
        let names = ["joseph",'john','megha','nadhiya'];
        return names.map(name => {
            return (
            <Namebox name={name} key={name}/>
            );
        })
    }


    render (){
        return (this.sayHello());
    }

};

export default NamesBox;

Failed to compile ./src/NamesBox.js Line 21:5: 'Namebox' is not defined react/jsx-no-undef无法编译 ./src/NamesBox.js Line 21:5: 'Namebox' is not defined react/jsx-no-undef

Search for the keywords to learn more about each error.搜索关键字以了解有关每个错误的更多信息。

namebox is a function not a component. namebox是一个函数而不是一个组件。 You are trying to invoke it inside the sayHello function as a component.您正试图在sayHello函数中将其作为组件调用。 Try this.namebox(name) instead.试试this.namebox(name) You are not suppose to create a component within a component so namebox is just a function and it should start with a lower case letter.您不应该在组件内创建组件,因此namebox只是一个函数,它应该以小写字母开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM