因此,当谈论类组件时,这是非常不言自明的,因为它们是全局 React 对象的一部分,但是它应该与每个功能组件一起导入背后的原因是什么? 是否考虑了捆绑商?
我已经编码了 5 个月了,所以如果我的问题的答案很明显,我很抱歉,并感谢您的关注。
最佳答案
正如 React 文档 ( https://reactjs.org/docs/jsx-in-depth.html#react-must-be-in-scope ) 中所述:
Since JSX compiles into calls to React.createElement, the React library must also always be in scope from your JSX code.
如果 React 不在范围内,React.createElement
将失败。
关于javascript - 为什么编写功能组件时应该将 React 纳入范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60950898/