// 接口
interface IHellProps {
message?: string
}
// message 只能是string或者undefined
// 过时,没有默认props
// const Hello = (props: IHellProps) => {
// return <h2>{props.message}</h2>
// }
// FunctionComponent 添加默认属性
const Hello: React.FunctionComponent<IHelloProps> = (props: IHelloProps) => {
return <h2>{props.message}</h2>
};
TS应该就泛型比较难写
React.FunctionComponent 是一个函数组件 => 简写 React.FC
里面有定义的各种方法之类
// 添加默认props
Hello.defaultProps = {
message: '冲冲冲'
};
export default Hello