I noticed that I've implemented API services using three different approaches for some of the hobby Apps I've built (probably following different tutorials).
1st approach - using classes
export default class APIService {
public getItems() {
return fetch(EXAMPLE_URI);
}
}
With this approach you have to import the service and create a new Instance to use it. (or maybe make a singleton)
2nd approach - using classes with static functions
export default class APIService {
static getItems() {
return fetch(EXAMPLE_URI);
}
}
Now you just can import APIService and use it directly like APIService.getItems()
3rd approach - exporting functions
export const getItems = () => fetch(EXAMPLE_URI);
With this approach you can just import the functions you actually need
Are there any major downsides to either of these? or is it just personal preference?
Aucun commentaire:
Enregistrer un commentaire