【问题标题】:React Class components vs Functional components [duplicate]反应类组件与功能组件[重复]
【发布时间】:2019-10-09 04:30:16
【问题描述】:

在您的组件中需要使用statelifecycle methods 时,React16 之前,class components 被用于functional components。 在最新版本中,React 引入了 HooksEffects,我们可以在 functional components 中使用 statelifecycle methods

那么class components 仍然存在有什么原因吗?是否有任何情况我们仍然必须选择class components 而不是functional

【问题讨论】:

    标签: reactjs react-16


    【解决方案1】:

    Here你可以看到你需要类组件的情况

    您需要类组件的最常见情况是,如果您想创建一个ErrorBoundary,您将需要一个类组件,因为您无法使用钩子实现componentDidCatch……但是!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-18
      • 2020-11-30
      • 1970-01-01
      • 2021-03-13
      • 2021-12-12
      相关资源
      最近更新 更多