Answers for "js es6 dynamic import default"

1

js es6 dynamic import default

// something.js

export const hi = (name) => console.log(`Hi, ${name}!`)
export const bye = (name) => console.log(`Bye, ${name}!`)
export default () => console.log('Hello World!')

We can use import() syntax to easily and cleanly load it conditionally:
// other-file.js

if (somethingIsTrue) {
  import('./something.js').then((module) => {
    // Use the module the way you want, as:
    module.hi('Erick') // Named export
    module.bye('Erick') // Named export
    module.default() // Default export
  })
}
Posted by: Guest on January-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language