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

326
Views
Error no capturado (en promesa): Llamada de gancho no válida. Los ganchos solo se pueden llamar dentro del cuerpo de un componente de función

Aplicación.js:

 function App() { PreProcess(); const user = useSelector(selectUser); // user initialized to null return user ? ( <p>{user}</p> ) : (<p>Authenticating and Authorizing</p>) } export default App;

preProceso.js:

 export const PreProcess = async () => { await readEnvVars(); // read env vars in local json file Auth(); // need environment variables for authentication and authorization }

autenticación.js

 export const Auth = async () => { const dispatch = useDispatch(); // some logic for authentication and authorization to get the user dispatch(setUser(userId)); }

error recibido

Error no capturado (en promesa): Llamada de gancho no válida. Los ganchos solo se pueden llamar dentro del cuerpo de un componente de función.

en auth.js:

const dispatch = useDispatch();

¿Por qué me sale este error y cómo solucionarlo?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Los ganchos no se pueden llamar dentro de funciones simples de javascript, solo dentro de otros ganchos o en componentes de funciones.

Referencia: https://reactjs.org/docs/hooks-rules.html

about 4 years ago · Juan Pablo Isaza Report

0

Resolví esto moviendo const dispatch = useDispatch(); hasta App.js y pase la variable dispatch como argumento para que el método lo necesite.

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