freeCodeCamp/guide/chinese/certifications/front-end-libraries/react/pass-props-to-a-stateless-f.../index.md

48 lines
839 B
Markdown
Raw Normal View History

---
title: Pass Props to a Stateless Functional Component
localeTitle: 将道具传递给无状态功能组件
---
## 将道具传递给无状态功能组件
### 提示1
在Calendar组件中定义一个名为date的prop如下所示
```jsx
<CurrentDate date={Date()} />
```
\`
### 提示2
语法prop.propName用于呈现prop。
### 解
在Calendar组件中按如下方式指定一个名为date的prop并在Calendar组件中呈现它
```jsx
const CurrentDate = (props) => {
return (
<div>
<p>The current date is: {props.date}</p>
</div>
);
};
class Calendar extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h3>What date is it?</h3>
<CurrentDate date={Date()} />
</div>
);
}
};
```