|
export const getData = (url) => { |
|
return fetch(url) |
|
.then(checkResponse) |
|
.catch((err) => { |
|
throw new Error(`fetch getData failed ${err}`); |
|
}); |
|
}; |
|
|
|
export const postData = (data) => { |
|
return fetch('/match-court', { method: 'POST', body: data }) |
|
.then(checkResponse) |
|
.catch((err) => { |
|
throw new Error(`fetch getData failed ${err}`); |
|
}); |
|
}; |
These two functions are very similar. You can add an options object argument to your first function and only need one fetch wrapping function.
CourtWatch/public/utils/fetch.js
Lines 11 to 25 in 24e5065
These two functions are very similar. You can add an options object argument to your first function and only need one fetch wrapping function.