首页 > 解决方案 > React.FunctionComponent 和普通的 JS 函数组件有什么区别?

问题描述

这两个例子完成了同样的事情。但是引擎盖下有什么区别?我了解功能组件与 React.Component 和 React.PureComponent,但我无法找到有关React.FunctionComponent.

React.FunctionComponent

const MyComponentA: React.FunctionComponent = (props) => {
  return (
    <p>I am a React.FunctionComponent</p>
  );
};

纯 JS 函数组件:

const MyComponentB = (props) => {
  return (
    <p>I am a plain JS function component</p>
  );
};

标签: javascriptreactjstypescript

解决方案


引擎盖下没有区别。第一个是使用 TypeScript 语法来指示类型,React.FunctionComponent但它们都是普通的 JS 函数组件。


推荐阅读