Last active
November 7, 2019 15:00
-
-
Save chrisgfortes/7823cfc613aee61f93f7202d50866fb5 to your computer and use it in GitHub Desktop.
Import/Export objects in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
key1: () => 'Key 1', | |
key2: () => 'Key 2', | |
}; | |
import all, { key1 } from 'index'; | |
// Result | |
// all = { key1, key2 } | |
// key1 = () => {} | |
export default { | |
key1: () => 'Key 1', | |
key2: () => 'Key 2', | |
}; | |
import all, { key1 } from 'index'; | |
// Result | |
// all = { key1, key2 } | |
// key1 = undefined | |
export { | |
key1: () => 'Key 1', | |
key2: () => 'Key 2', | |
}; | |
import all, { key1 } from 'index'; | |
// Result | |
// all = undefined | |
// key1 = () => {} | |
const File1 = () => 'File 1'; | |
const File2 = () => 'File 2'; | |
// index.js | |
export { default as File1 } from './File1'; | |
export { default as File2 } from './File2'; | |
import All, { File1, File2 } from 'index'; | |
// Result | |
// all = undefined | |
// File1 = () => {} | |
// File2 = () => {} | |
const File1 = () => 'File 1'; | |
const File2 = () => 'File 2'; | |
// index.js | |
export { default as File1 } from './File1'; | |
export { default as File2 } from './File2'; | |
import * as all from 'index'; | |
// Result | |
// all = { File1 = () => {}, File2 = () => {} } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment