Подскажите, как организовать fetch запрос в формате модуля.
Есть модуль:
function status(response) {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response);
} else {
return Promise.reject(new Error(response.statusText));
}
}
function json(response) {
return response.json();
}
fetch("https://api.covid19api.com/summary", {
"method": "GET"
})
.then(status)
.then(json)
.then((data) => {
cb(data);
})
.catch((error) => {
console.log(error.name);
console.log('Ошибка: ' + error.message);
console.log(error.response);
});
export default function cb(data) {
return data;
}
Он импортируется в index.js
import cb from './modules/getData';
console.log(cb());
Но в консоль выводится undefined. Подскажите, пожалуйста, что я делаю не так. В чем ошибка? Если я пишу неправильно, то скажите, как можно организовать fetch запрос модулем, чтобы передавать в него различные url и другие параметры