[英]Component is not rendering
I'm working through the React 16 course on Udemy. 我正在学习有关Udemy的React 16课程。 We are using Codepen to create our first React apps in the course. 我们正在使用Codepen在课程中创建我们的第一个React应用程序。 Although the instructor is able to render the component in the video, I follow his code and it doesn't render. 尽管讲师可以渲染视频中的组件,但我遵循他的代码,但无法渲染。 Here's the HTML, CSS, and JS code: 这是HTML,CSS和JS代码:
HTML: HTML:
<div class="person">
<h1>Your name</h1>
<p1>Manu</p1>
</div>
CSS: CSS:
.person {
margin:10px;
box-shadow:2px 2px #ccc;
border: 1px solid #eee;
padding: 20px;
width: 200px;
display: inline-block;
}
JavaScript: JavaScript:
function Person(){
return(
<div className="person">
<h1>Your name</h1>
<p1>Tristan</p1>
</div>
);
}
ReactDOM.render(<Person/>, document.querySelector('#p1'));
You have a misprint: Persan
vs Person
. 您的印刷错误: Persan
vs Person
。
Also instead of class
you should use className
because JSX
is just a javascript
and keyword class
is reserved. 另外,应该使用className
而不是class
,因为JSX
只是一个javascript
并且保留了关键字class
。
Also instead of p1
element I believe you should use either p
or some custom component which will have a name started with a capital letter. 另外,我相信您应该使用p
或某些自定义组件(而不是p1
元素),其名称应以大写字母开头。
function Person() { return ( <div className="person"> <h1>Your name</h1> <p>Tristan</p> </div> ); } ReactDOM.render(<Person/>, document.querySelector('#p1'));
.person{ margin:10px; box-shadow:2px 2px #ccc; border: 1px solid #eee; padding: 20px; width: 200px; display: inline-block; }
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> <div id="p1"></div>
The issue is due to the typo Persan
in the component declaration. 该问题归因于组件声明中的错字Persan
。 It should be 它应该是
function Person(){
return(
<div className="person">
<h1>Your name</h1>
<p1>Tristan</p1>
</div>
);
}
ReactDOM.render(<Person/>, document.querySelector('#p1'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.