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

200
Vistas
Custom hook is not a function React

When I try and call a function from my custom hook I get back an error when the screen loads saying setAuth is not a function.

useAuth.js

import { useContext } from "react";
import AuthContext from "../context/AuthProvider";
const useAuth = () => {
  return useContext(AuthContext);
}
export default useAuth;

login.js

import useAuth from '../hooks/useAuth';
...
const Login = () => {
 const { setAuth } = useAuth();
 ....
 setAuth({ email, password, accessToken });
 ...
 }

If I try and display typeof(setAuth) I get undifined.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to ensure your AuthContext has a setAuth function. Where you are calling your AuthContext.Provider you must provide setAuth function in the value prop

<AuthContext.Provider value={{ setAuth }}>

You can then access setAuth

const useAuth = () => {
 const { setAuth } = useContext(AuthContext);
 return setAuth
}

login.js

const Login = () => {
 const setAuth = useAuth();
 ....
 setAuth({ email, password, accessToken });
 ...
 }
about 4 years ago · Juan Pablo Isaza Denunciar
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