import { useEffect, useState } from "react"; import { Redirect } from "react-router-dom"; import login from "../apis/user.api"; const INIT_USER = { email: "", password: "", }; const Login = () => { // const { error, loading, login } = useAuth(); const [user, setUser] = useState(INIT_USER); const [disabled, setDisabled] = useState(true); const [error, setError] = useState(""); const [success, setSuccess] = useState(false); useEffect(() => { const isUser = Object.values(user).every((el) => Boolean(el)); isUser ? setDisabled(false) : setDisabled(true); }, [user]); function handleChange(event) { const { name, value } = event.target; setUser({ ...user, [name]: value }); } async function handleSubmit(e) { e.preventDefault(); try { // setLoading(true); // setError(""); const data = await login(user); console.log(data); setSuccess(true); } catch (error) { // catchErrors(error, setError); } finally { // setLoading(false); } } if (success) { return ; } const { email, password } = user; return (
로그인
); }; export default Login;