e.preventDefault() 코드가 추가 되어야
입력된 값이 데이터에 추가가 됨
비동기 처리: 데이터 처리나 서버 요청과 같은 비동기 작업을 수행할 때,
제출 이벤트를 막고 async/await와 함께 e.preventDefault()를 사용하여
비동기 작업이 완료될 때까지 기다릴 수 있습니다.
이렇게 함으로써 데이터가 제대로 처리되지 않은 상태에서 페이지가
새로고침되는 것을 방지하고, 비동기 작업이 완료된 후에
상태를 업데이트하거나 다른 동작을 수행할 수 있습니다.
const handleSubmit = async (e) => {
e.preventDefault(); //새로고침 방지
try {
const nextNum = indexNum + 1;
// console.log(e); //값 들어 오는지 확인
await addDoc(collection(fireStore, 'users'), {
content: formValue,
index: nextNum,
isdone: isDoneValue,
});
setindexNum(nextNum);
setisDoneValue(true);
} catch (error) {
console.error('전송 에러', error);
}
//작성한걸 다시 빈 값으로 설정
setFormValue("");
}