freeCodeCamp/guide/chinese/certifications/front-end-libraries/react/create-a-react-component/index.md

32 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Create a React Component
localeTitle: 创建一个React组件
---
## 创建一个React组件
## 提示1
* 你会一直看到这些React类组件所以现在是适应它们的好时机。请记住在本练习中您不必定义组件只需要使一个函数在标记的行之间返回一个小的html。
* 记住上一节并返回一个“div”元素其中包含带有文本Hello React的“h1”。
* “div”元素有一个孩子所以记得关闭所有标签。
## 解
```javascript
class MyComponent extends React.Component {
constructor(props) {
super(props);
}
render() {
// change code below this line
return (
<div>
<h1>Hello React!</h1>
</div>
);
// change code above this line
}
};
```
请注意您不需要在文本周围加上引号因为在使用JSX时它被视为HTML。还要检查以确保您的拼写大小写和标点符号正确无误如果所有这些代码看起来很奇怪请在freeCodeCamp上查看Javascript ES6上的一些很棒的资料。