类组件

  • 定义类组件
  1. interface State {
  2. }
  3. interface Props {
  4. }
  5. class 类组件名 extends React.Component<Props, State> {
  6. render(){
  7. return <div></div>
  8. }
  9. }

函数组件

  • 函数组件定义
  1. interface Props {
  2. }
  3. interface State {
  4. }
  5. const 函数组件名 = (props: Props) => {
  6. return <div></div>
  7. }

函数组件定义状态

  • const [ 状态 , set状态] = useState<状态类型>( 数据 )