Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
¿Cuál es la alternativa para usar ganchos dentro del componente que no es React?

Soy nuevo en React y tengo esta función.

 import Axios from "axios"; const UserService = { getUserRole: (access_token: string = "") => { return Axios({ method: "get", url: "https://<url>/user/role", headers: { "Authorization": `Bearer ${access_token}` } }).then((response) => { return response.data; }).catch((error) => { console.log(error); }); } } export default UserService

El getUserRole es utilizado constantemente por otro componente, por ejemplo

 import UserService from "../../../services/authentication/userService"; import { useAuth } from "react-oidc-context"; ... const auth = useAuth(); UserService.getUserRole(auth.user?.access_token);

Como puede ver, tengo que pasar constantemente access_token de useAuth . ¿Hay alguna forma en que pueda llamar a useAuth dentro de mi UserService para no tener que pasar constantemente el access_token de acceso de mi componente?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!