import React, { useRef, useState, useEffect } from "react"; import axios from "../api/axios"; const LOGIN_URL = "/login"; const Login = () => { const userRef = useRef(); const errRef = useRef(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [errMsg, setErrMsg] = useState(""); const [success, setSuccess] = useState(false); useEffect(() => { userRef.current.focus(); }, []); useEffect(() => { setErrMsg(""); }, [username, password]); const handleSubmit = async (e) => { e.preventDefault(); const response = await axios.post( LOGIN_URL, `username=${username}&password=${password}`, { headers: { "content-type": "application/x-www-form-urlencoded", withCredentials: true, }, } ); setUsername(""); setPassword(""); setSuccess(true); }; return success ? (

Успешна најава!


Оди на почетната страница

) : (

{errMsg}

Најава

setUsername(e.target.value)} value={username} required /> setPassword(e.target.value)} value={password} required />
); }; export default Login;