import * as react from 'react' 与 import react from 'react' 有什么区别 [英] What is the difference between import * as react from 'react' vs import react from 'react'

查看:33
本文介绍了import * as react from 'react' 与 import react from 'react' 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 React 或一般的编码背景不熟悉.而且我不确定这些陈述之间有什么区别

I am new to React or the coding background in general. And I am not sure what is the difference between the statements

import * as react from 'react'

import react from 'react'

提前致谢!

推荐答案

最常用的 import 有 3 种类型.

There are 3 types of most import commonly used imports.

类型 1

import * as A from 'abc';

这将导入在 abc 中标记为导出的所有内容.您可以使用以下代码访问它们.

This will import everything which is marked as export in abc. You can access them using below code.

A.Component 

类型 2

import {A} from 'abc';

这将从 abc 导入 A,包含如下内容:

This will import A from abc, containing something like this:

export const A = () => {};

类型 3

import A from 'abc';

这会将 abc 的默认导出导入为 A.导出可以如下所示:

This will import the default export from abc as A. The export can look like this:

const B = () => {}; // The name "B" is not exported, only the value.

export default B;  // at the end of component

这篇关于import * as react from 'react' 与 import react from 'react' 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆