Answer the question
In order to leave comments, you need to log in
Return a value from a promise and export it to use in other modules?
I use dynamic import of modules in the module depending on the conditions. It returns a promise ( 2ality.com/2017/01/import-operator.html) how can I export the result from the promise from here without creating a global variable?
so of course it doesn't work.
if (условие) {
import('./mymodule')
.then(module => {
if (module.value) {
const res = module.value
return res;
}
})
} else {
import('./mymodule2')
.then(module => {
if (module.value2) {
const res = module.value2
return res;
}
})
}
export default res;
Answer the question
In order to leave comments, you need to log in
What's the problem with using it require
?
function moduleIf(условие){
if (условие) {
let res = require('./mymodule')
return res;
} else {
let res = require('./mymodule2')
return res;
}
}
export default moduleIf;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question