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

220
Views
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
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!