You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
516 B
27 lines
516 B
import React from "react";
|
|
import ReactDOM from "react-dom";
|
|
|
|
// 组件的属性
|
|
|
|
type Props = { name: string; age?: number }
|
|
class Hello extends React.Component<Props> {
|
|
// 在类组件中给 age 添加默认属性
|
|
static defaultProps: Partial<Props> = {
|
|
age: 20
|
|
}
|
|
|
|
render() {
|
|
const { name, age } = this.props
|
|
return (
|
|
<div>我是:{name}, 我 { age } 岁</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const App = () => <div>
|
|
<Hello name="Ken"/>
|
|
</div>
|
|
|
|
ReactDOM.render(<App />, document.getElementById('root'))
|