DEV Community

Discussion on: React: Writing a custom API hook

Collapse
 
diogomqbm_ profile image
Diogo Mafra • Edited

Why did you decided to use APIService abstraction as a class? Couldn't you make an object with each ajax magic on it? That way you could follow your functional approach. Congratz on the post! Awesome abstraction, ty for sharing!


const APIService = {

  loadUsers: async () => {
     // ajax magic
  },

  loadUsersById: async (id) => {
     // ajax magic
  }

}

export default APIService

Collapse
 
patrixr profile image
Patrick R

Valid point, in part a force of habit, and in another I do have a tendency to inherit base service classes, as seen here. That part kinda got lost as I was trying to simplify things.

Glad you like the hook :)