[英]What does import {} from '.' do?
I was looking at some source code of a library and I saw this import我正在查看一个库的一些源代码,我看到了这个导入
import {SheetsRegistry, JssProvider, withStyles} from '.'
What does this do?这是做什么的? How does it import from '.'
它如何from '.'
导入? ?
The code you shared imports those declarations from index.js in the same directory.您共享的代码从同一目录中的index.js导入这些声明。
index.js:索引.js:
// @flow
import withStyles from './withStyles'
export {ThemeProvider, withTheme, createTheming, useTheme} from 'theming'
export {default as createUseStyles} from './createUseStyles'
export {default as JssProvider} from './JssProvider'
export {default as jss} from './jss'
export {SheetsRegistry, createGenerateId} from 'jss'
export {default as JssContext} from './JssContext'
export {default as styled} from './styled'
export {default as jsx, create as createJsx} from './jsx'
export {withStyles}
// Kept for backwards compatibility.
export default withStyles
In this example, index.js
is being used to re-export some of the declarations within the src
directory.在此示例中, index.js
用于重新导出src
目录中的一些声明。 This pattern makes it easier to move the declarations around without having to rewrite many imports.这种模式使移动声明变得更容易,而不必重写许多导入。
******The difference between named exports and default exports.****** ******命名导出和默认导出的区别。******
1-named exports 1-命名出口
export function, constant, variable...etc in Constant.js Constant.js中的导出函数、常量、变量...等
export const CREATE = 'CREATE';
export const DELETE = 'DELETE';
import like this in index.js在index.js中这样导入
import {CREATE,DELETE} from './Constants';
2-default exports 2-默认导出
export it in Constant.js在Constant.js中导出
const update = ()=> 'UPDATE'
export default update();
and import like this in index.js并在 index.js 中像这样导入
import UPDATE from './Constants';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.