If you dig a few files deeper into React's source code, you'll find this file where the React
object we import many times a day is constructed and exported.
(如果您深入研究React的源代码中的几个文件,您会发现该文件是我们每天多次导入的React
对象在其中构建和导出的。)
At line 66 :(在第66行 :)
const React = {
...
// just a few examples of what's in here...
Component,
useState,
Fragment,
...
}
And then by the end of this file, the object is exported as the default export.
(然后,在此文件末尾,该对象将作为默认导出导出。)
Inside this object, you'll find many familiar components/methods, including Component
, Fragment
, useState
, etc. These are declared as properties of the React
object, which is why we can:
(在此对象内,您会发现许多熟悉的组件/方法,包括Component
, Fragment
, useState
等。这些被声明为React
对象的属性,因此我们可以:)
And as part of the React
object, they are exported implicitly , which is why we can:
(并且作为React
对象的一部分,它们被隐式导出,这就是为什么我们可以:)
Component
is not a named export in the module (there is only one export
statement in the module and that is default export).
(Component
不是模块中的命名导出(模块中只有一个export
语句,这是默认导出)。)
Though the import statement does make it look like one.(尽管import语句确实使它看起来像一个。)
Hope this helps!
(希望这可以帮助!)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…