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

219
Vistas
Error with useAuth working with react router dom in react js

i am begginer in react , i need to protect a page with my login , but this not works , this is the error : Uncaught TypeError: Auth_context__WEBPACK_IMPORTED_MODULE_1_.useAuth() is null here is my code...

import { useState, useCallback} from "react";
import { useNavigate } from "react-router-dom";
import { useAuth } from "./Auth.context";

const Login = () => {
  const [username, setUsername] = useState("");
  const { setUser } = useAuth();
  const navigate = useNavigate();

  const login = useCallback((e) => {
    e.preventDefault();
    setUser({ username });
    navigate("/home");
  }, [setUser, username]);

  return(
    <div>
      <h1>Inicie sesion</h1>
      <form onSubmit={login}>
        <input value={username}
          onChange={(e) => setUsername(e.target.value)}
          placeholder="Escriba el nombre de usuario"
        />
        <button type="submit">Login</button>
      </form>
    </div>
  );
};

export default Login
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