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
664 B

import ReactDOM from "react-dom";
// 函数的默认值
type Props = { name: string; age?: number}
// const Hello: FC<Props> = ( { name, age } ) => (
// <div>我是:{name}, 我 { age } 岁</div>
// )
// 提供默认属性
// Hello.defaultProps = {
// age: 18 // age 是可选属性,当没给 age 的值时,默认 age 的值为 18
// }
// 简化写法
const Hello = ( { name, age = 18 }: Props ) => ( // 给 age 添加默认值 18
<div>{name}, { age } </div>
)
const App = () => <div>
{/* name 是必填的 */}
<Hello name="jack" />
</div>
ReactDOM.render(<App />, document.getElementById('root'))