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

107
Vistas
How to call a custom hook from the onclick handler function in React

I am having a custom hook to fetch data from the API. Invoking the custom hook outside handleSubmit works but inside handleSubmit it does not work.

const Login = () => {
  const userRef = useRef();
  const [user, setUser] = useState("");
  
  const isUser = useLoginHook(user); **//// This works**

  const handleSubmit = async (e) => {

    e.preventDefault();
     const isUser = useLoginHook(user); **///// This does not work**

  };

  return (
    <>
       <main className="App">
          <form onSubmit={handleSubmit}>
            <input
              type="text"
              id="username"
              ref={userRef}
              autoComplete="off"
              onChange={(e) => setUser(e.target.value)}
              value={user}
              required
              aria-invalid={validName ? "false" : "true"}
              aria-describedby="uidnote"
              onFocus={() => setUserFocus(true)}
              onBlur={() => setUserFocus(false)}
            />
      </form>
      </main>
    </>
  );
}; 

I am getting error "React hook is called in function that is neither a React function or a custom React Hook function"

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