Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

286
Vistas
Creating service in React Typescript using axios

There are two different ways to create a service and call from the required funtional component.

1.

export const userProfileService = {

    ResetPassword: async (userId: string) => {
        var response = await http.get<string, boolean>(`UserProfile/ResetPassword?userId=${userId}`);
        return response;
    }
}
class UserProfileService {

    readonly userProfilePath = 'UserProfile';

    resetPassword = async (userId: string) => {
        var response = await http.get<string, boolean> 
      (`${this.userProfilePath}/ResetPassword?userId=${userId}`);
        return response;
    }
    export default new UserProfileService();


**The question is which way is better and optimized way? or better convention?**
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Why not just make it a function?

export const resetPassword: async (userId: string) => {
         return await http.get<string, boolean>(`UserProfile/ResetPassword?userId=${userId}`);
    }

Putting the function in a class or an object seems to only complicate and obfuscate in this case. It looks very much like a C#-influenced style. Not terrible or wrong per se, but a bit verbose and complicated when all you need is a pure function.

Also, you should use let or const keyword instead of var because of differences in scope. You're not making any errors in the code above because var is function-scoped, but it's almost always better to use const (or let if you need to modify it).

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda