Files
2018-10-16 21:32:40 +05:30

48 lines
839 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
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>
);
}
};
```