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

281
Views
¿Cómo usar una clase de servicio en un gancho de reacción?

Estoy tratando sin éxito de inicializar y usar una clase de servicio desde un gancho React. La clase de servicio se parece a:

 export class ExampleService { constructor(private exampleParams: string[]) {} isPresent(exampleName: string): boolean { return this.exampleParams.includes(exampleName); } getAll(): string[] { return this.exampleParams; } setExamples(exampleParams: string[]): void { this.exampleParams = exampleParams; } }

Y luego, en el gancho, estoy tratando de usar esta clase:

 import { ExampleService } from '../somewhere/example-service'; import { useContext } from 'react'; import { ExampleContext } from '../contexts/example-context'; export const useExample = () => { const { currentExamples } = useContext(ExampleContext); const checkExamples = new ExampleService(currentExamples); return [checkExamples.isPresent]; };

Sin embargo, TypeError: Cannot read property 'exampleParams' of undefined cuando intento probar el código :/ (el error está en la función isPresent anterior).

¿Qué estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
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!