Javascript 为什么导出withAlert(警报)会导致错误,而withAlert()(警报)会起作用?

Javascript 为什么导出withAlert(警报)会导致错误,而withAlert()(警报)会起作用?,javascript,reactjs,Javascript,Reactjs,在警报中组件通过以下方式导出: export default withAlert(Alerts) 这是导致错误的原因: The above error occurred in one of your React components: in Unknown (created by App) in Provider (created by App) in Provider (created by App) in App Consider adding an er

警报中
组件通过以下方式导出:

export default withAlert(Alerts)
这是导致错误的原因:

The above error occurred in one of your React components:
    in Unknown (created by App)
    in Provider (created by App)
    in Provider (created by App)
    in App

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb me/react-error-boundaries to learn more about error boundaries. react-dom.development.js:21810:13
Error: Objects are not valid as a React child (found: object with keys {$$typeof, render}). If you meant to render a collection of children, use an array instead.
    in Unknown (created by App)
    in Provider (created by App)
    in Provider (created by App)
    in App 2 main.js line 753 > eval:14729:15
阅读后,导出更改为以下内容,并且可以正常工作:

export default withAlert()(Alerts)
实质上:

  • 这个变化正确吗
  • 那次改变做了什么
  • 为什么有必要
      • 对。没错
      • 由于react alerts的api发生了更改,您应该更新代码。此链接中描述了更改信息
      • 要遵循已发布的api,因为您使用了它们的代码:)。我猜他们在括号内添加了一些参数来定制警报。但重要的是youtube上的指南使用了比当前版本更旧的版本

      因此,如果我理解正确:
      withAlert()
      返回一个函数,该函数与前面的
      withAlert
      函数类似?是的,几乎相同。