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

416
Views
¿Por qué no se puede pasar una función React setState como parámetro a una clase?

Tengo esta clase en mi proyecto React:

utils.ts

 export class BtnManager { private setState: Function constructor(setState: React.Dispatch<React.SetStateAction<IBtnProps>>) { this.setState = setState; } public updateBtn(text?: string, disabled?: boolean, rest?: IBtnProps) { if (!rest) rest = INITIAL_BUTTON_STATE; if (text && disabled) { this.setState({ ...rest, text, disabled, }); } else { this.setState(rest); } } }

Y este useEffect en un componente

Juego.tsx

 useEffect(() => { const btnManager = new BtnManager(setBtnProps); const updateBtn = btnManager.updateBtn if (!accountId) { updateBtn(); } else if (!tokenOut.info) { updateBtn('Select a Pool', true); } }, [accountId, tokenOut.info] }

Pero recibo este error en la consola del navegador:

Uncaught TypeError: Cannot read properties of undefined (reading 'setState')

Paso las funciones this.setState a los componentes todo el tiempo, pero esta es la primera vez que intento crear una clase para ayudar a administrar el estado. cuando se usa en el método updateBtn a través de useEffect, se arroja el error anterior. No estoy seguro de lo que está pasando aquí, se agradece cualquier idea.

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!