re: React: Writing a custom API hook VIEW POST


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


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 :)

code of conduct - report abuse