I am new to the react.js and javascript world.
I have a promise object called articles
, and I want to export default
the variable post
inside (or outside) the then
block.
Approach 1:
articles.then((response) => {
let posts = response.map(...);
}, (error) => {
console.log(error);
});
export default posts; // undefined;
Approach 2:
let posts;
articles.then((response) => {
posts = response.map(...);
}, (error) => {
console.log(error);
});
export default posts; // undefined;
Approach 3:
articles.then((response) => {
export let posts = response.map(...); // Parsing error: 'import' and 'export' may only appear at the top level
}, (error) => {
console.log(error);
});
Any suggestions?