gpt4 book ai didi

javascript - 为什么导出 withAlert(Alerts) 会导致错误,但 withAlert()(Alerts) 却有效?

转载 作者:行者123 更新时间:2023-12-02 22:34:22 28 4
gpt4 key购买 nike

Brad's tutorial Alerts 组件使用以下方式导出:

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

阅读后react-alerts documentation导出更改为以下内容并且有效:

export default withAlert()(Alerts)

本质上:

  • 此更改正确吗?
  • 这个改变做了什么?
  • 为什么有必要?

最佳答案

关于javascript - 为什么导出 withAlert(Alerts) 会导致错误,但 withAlert()(Alerts) 却有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58785252/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com