Reputation: 309
how to import a value of the promised based function to another module?
// index.js file:
import test from "./test";
console.log(test) // expected result should be "delectus aut autem" - now getting Promise object
// test.js file:
var test = fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
.then(function (data) {
return data.title
});
export default test
working example: https://js-njm471.stackblitz.io
Upvotes: 0
Views: 100
Reputation: 16586
Since test
is a promise, you simply have to handle it as such after you import it.
test.then(data => {
console.log(data);
});
Upvotes: 1