new meetup form - data

리리·2021년 8월 5일

TIL

목록 보기
14/22

function NewMeetupForm에서 form submit event인 submitHandler, 각 폼 요소는 ref형식으로 전달해서 useRef()로 레퍼 요소 만들어 submitHandler에 넣기

const titleInputRef = useRef();
const imageInputRef = useRef();
const addressInputRef = useRef();
const descriptionInputRef = useRef();

function submitHandler(event) {
    event.preventDefault();

    const entertedTitle = titleInputRef.current.value;
    const enteredImage = imageInputRef.current.value;
    const enteredAddress = addressInputRef.current.value;
    const enteredDescription = descriptionInputRef.current.value;

    const meetupData = {
        title: entertedTitle,
        image: enteredImage,
        address: enteredAddress,
        description: enteredDescription,
    };

    console.log(meetupData);
}

0개의 댓글