import { useState, useEffect } from 'react'; import BtnGroup from "../Buttons/BtnGroup"; import styles from "./form.module.scss"; import { useParams } from 'react-router-dom'; import subjectApi from '../../apis/subject.api'; import catchErrors from '../../utils/catchErrors.js'; const SubjectForm = () => { const { subjectId } = useParams(); const [error, setError] = useState(""); const [subject, setSubject] = useState({ lectureName: "", prof: "", classRoom: "" }) const [disabled, setDisabled] = useState(true) useEffect(() => { let isMounted = true; const checkInfo = { lectureName: subject.lectureName } if (isMounted) { const isSubject = Object.values(checkInfo).every((el) => Boolean(el)); isSubject ? setDisabled(false) : setDisabled(true); } return () => { isMounted = false; } }, [subject]) function handleChange(e) { const { name, value } = e.target setSubject({ ...subject, [name]: value }) } async function handleSubmit(e) { e.preventDefault(); try { if (subjectId) { //수정함수 실행 } else { await subjectApi.addsubject(subject) } } catch (error) { catchErrors(error, setError) } } return ( <>