import Component from 'react'
与
相同
import React from 'react'
那是因为你正在导入 React 包的默认导出,你可以随意命名它。
import React, { Component } from 'react'
这个“组件”指的是 React.Component,你是从 'react' 导入“组件”加上默认导出。
想象有一个名为exports.js 的具有多个导出的文件
const DefaultExport = () => null
export const OtherExport = () => null
export const AnotherExport = () => null
export default DefaultExport
您可以使用
导入您的组件
import something from './exports' //this is DefaultExport
import { OtherExport } from './exports' //OtherExport
import { AnotherExport as RandomExport } from './exports' //AnotherExport
import * as Exports from './exports' //you are importing all the exports
对于最后一种情况import * as Exports from './exports',您可以访问和使用文件中的所有导出,例如
Exports.default //refer to default export
Exports.OtherExport //refer to OtherExport
Exports.AnotherExport //refer to AnotherExport