fix: 설계빈도 에러 메세지 상태 초기화 추가
This commit is contained in:
@@ -67,15 +67,7 @@ export function VerticalTable({
|
||||
}: UiTableProps) {
|
||||
const [cur, setCur] = useState<number>(1);
|
||||
const [formData, setFormData] = useState<{ [key: string]: string | number | boolean }>({});
|
||||
const [errors, setErrors] = useState<{ [key: string]: string }>({}); // 에러 상태 추가
|
||||
|
||||
// 컴포넌트 언마운트 시 confirmToast 정리
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
// 컴포넌트가 언마운트될 때 global-confirm-toast ID를 가진 Toast 제거
|
||||
toast.dismiss("global-confirm-toast");
|
||||
};
|
||||
}, []);
|
||||
const [errors, setErrors] = useState<{ [key: string]: string }>({});
|
||||
|
||||
useEffect(() => {
|
||||
if (resetPageNo) {
|
||||
@@ -86,23 +78,19 @@ export function VerticalTable({
|
||||
|
||||
useEffect(() => {
|
||||
if (tableData.length > 0 && tableData[0]) {
|
||||
// 깊은 복사를 통해 새로운 객체 생성
|
||||
const newData = JSON.parse(JSON.stringify(tableData[0]));
|
||||
setFormData(newData);
|
||||
console.log("Form data initialized:", newData); // 디버깅용
|
||||
setErrors({});
|
||||
}
|
||||
}, [tableData]);
|
||||
|
||||
const handleInputChange = (id: string, value: string | number | boolean) => {
|
||||
console.log(`Input change: ${id} = ${value}`); // 디버깅용
|
||||
const newFormData = {
|
||||
...formData,
|
||||
[id]: value,
|
||||
};
|
||||
console.log("New form data:", newFormData); // 디버깅용
|
||||
setFormData(newFormData);
|
||||
|
||||
// 에러 메시지 초기화 (입력이 성공하면 에러 제거)
|
||||
if (errors[id]) {
|
||||
setErrors(prev => {
|
||||
const newErrors = { ...prev };
|
||||
@@ -111,7 +99,6 @@ export function VerticalTable({
|
||||
});
|
||||
}
|
||||
|
||||
// 폼 데이터가 변경될 때마다 부모에게 알림
|
||||
if (onFormDataChange) {
|
||||
onFormDataChange(newFormData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user