Есть модуль:
async function request(url, { method = 'GET', body = null, headers = {} }) {
console.log(method)
let loading = false;
let error = null;
let data = null;
try {
const response = await fetch(url, { method, body, headers });
const data_ = await response.json();
data = data_;
loading = true;
} catch (err) {
error = err.message;
loading = true;
}
return { loading, data, error }
}
export default request;
const topNews = request('http://localhost:5500/api/news/top/2');
Почему-то при вызове request()
выдает ошибку:
Unhandled Rejection (TypeError): Cannot read property 'method' of undefined
request('...', {})