小编Jon*_*han的帖子

React中导出接口Props的目的是什么(Typescript ver)

React Typescript Starter示例创建组件的创建组件部分,Typescript 中有一个基本的 React 组件:

// src/components/Hello.tsx

import * as React from 'react';

export interface Props {
  name: string;
  enthusiasmLevel?: number;
}

function Hello({ name, enthusiasmLevel = 1 }: Props) {
  if (enthusiasmLevel <= 0) {
    throw new Error('You could be a little more enthusiastic. :D');
  }

  return (
    <div className="hello">
      <div className="greeting">
        Hello {name + getExclamationMarks(enthusiasmLevel)}
      </div>
    </div>
  );
}

export default Hello;

// helpers

function getExclamationMarks(numChars: number) {
  return Array(numChars + …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×1

reactjs ×1

typescript ×1