【问题标题】:What advantage FC function component has over vanilla React function component?FC 函数组件比普通的 React 函数组件有什么优势?
【发布时间】:2022-01-15 19:37:20
【问题描述】:

我见过这个FC函数组件:

const LabelForm: FC<LabelFormProps> = ({
  labels,
  selectedID,
}) => {
  const selectedLabel = selectedID !== undefined && labels[selectedID];

通常我是这样实现的:

interface EventProps {
  lang: string;
  translations: Translation;
  eventId: string;
}

function Event(props: EventProps) {
  const { lang, translations, eventId } = props;

它只是一种语法糖,还是比普通的有任何优势?

【问题讨论】:

    标签: reactjs typescript next.js


    【解决方案1】:

    现在这实际上不是优势! CRA 实际上已经退回了这个标准,因此默认情况下它不再以默认的npx create-react-app --typescript 发布。

    这是一个讨论它的 GitHub 问题!

    本质上它隐含地暗示默认情况下总会有孩子,这不是必需的,并且可能会导致错误!

    https://github.com/facebook/create-react-app/pull/8177

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-12
      • 2019-05-24
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2014-04-09
      • 2019-07-20
      相关资源
      最近更新 更多