在React中命名为import [英] Named import in React

查看:93
本文介绍了在React中命名为import的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这一行:

import React, { Component } from "react";

为什么花括号只在Component周围而不是在'React'上?

why the braces are only around Component and not also on 'React'?

推荐答案

这是一个很好的答案,它解释了默认名称并命名为在ES6中导入

Here's a great answer that explains default and named imports in ES6

假设我们要导入一个名为Foo的类.如果要获取默认导出,则可以执行以下操作:

Let's say we have a class named Foo that I want to import. If I want to get the default export, I would do:

import Foo from './foo.js';

如果我想要foo文件中的特定功能,可以使用花括号.

If I wanted a specific function inside the foo file, I would use the curly braces.

import { fooFunction } from './foo.js';

注意,这不是React功能,而是ES6.您可能正在使用babel将代码从ES6转换为ES5.

Note, this isn't a React feature, but ES6. Likely you are using babel to transpile your code from ES6 to ES5.

这篇关于在React中命名为import的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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