졸업작품 진행 중 모달창을 닫는 함수에서 '정의되지 않음'일 수 있는 개체를 호출할 수 없습니다. 라는 에러가 계속 발생하였다.
type Prop = {
PostingCloseModal?: () => void
studyClass: string;
startTime: string;
endTime: string;
}
const createStudy = async () => {
const calenderList = {
content: content,
studyClass: studyClass,
startTime: startTime,
endTime: endTime,
};
try {
const access = localStorage.getItem('accessToken');
const response = await axios.post(`${apiUrl}/calender`, calenderList, {
headers: { Authorization: `Bearer ${access}` },
});
alert('완료되었습니다.')
PostingCloseModal(); //이부분!!
} catch (error) {
alert('입력값이 비어있습니다. 확인해주세요.');
}
}
구글링을 해보니 코드를 PostingCloseModal?: () => void
라고 작성하는건선택적 함수이이므로 PostingCloseModal이 없을수도 있으니 실행시킬 수 없어요
라는 의미라고 한다 그래서 ?를 지워봤더니 바로 된다~
type Prop = {
PostingCloseModal: () => void
studyClass: string;
startTime: string;
endTime: string;
}