• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

193
Vistas
Getting "Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')"

Screenshot of error, while console in google. That's the code I gave, and getting an unexpected error

const [email, setEmail] = useState("");
    const [password, setPassword] = useState("");
    const [error, setError] = useState(false);
    const [loading, setLoading] = useState(false);

    // useEffect(() => {
    //     const userInfo = localStorage.getItem("userInfo");

    //     if(userInfo){
    //         history.push("/mynotes");
    //     }
    // }, [history]);

    const submitHandler = async (e) => {
        e.preventDefault();
        console.log(email, password);

        try{
            const config = {
                headers: {
                    "Content-type": "application/json",
                },
            }; 
            setLoading(true);

            const { data } = await axios.post(
                "/api/users/login", 
                {
                    email, 
                    password
                },
                config
            );
            
            console.log(data);

            localStorage.setItem("userInfo", JSON.stringify(data));

            setLoading(false);
        }
        catch (error){
            setError(error.response.data.message);
        //     setLoading(false);
        }
[1]: https://i.stack.imgur.com/UVse7.jpg
almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda