form quiz

Juyeon Lee·2022년 5월 17일
0

REACT 리액트

목록 보기
34/65
  1. In a vanilla JS app, at what point in the form submission
    process do you gather all the data from the filled-out form?
    Right before the form is submitted.
  1. In a React app, when do you gather all the data from
    the filled-out form?
    As the form is being filled out. The data is all held in local state.

흠 한마디로 바닐라 자바스크립트에서는 submit 바로 하기 전에
data를 받는데 리액트에서는 폼에 입력되는 순간 로컬스테이트에 저장이 되는거구나... ?

  1. Which attribute in the form elements (value, name, onChange, etc.)
    should match the property name being held in state for that input?
    name property.
    function handleChange(event) {
        const {name, value, type, checked} = event.target
        setFormData(prevFormData => {
            return {
                ...prevFormData,
                [name]: type === "checkbox" ? checked : value
            }
        })
    }

여기보면 [name] 이렇게 되어있잖아?

  1. What's different about saving the data from a checkbox element
    vs. other form elements?
    A checkbox uses the checked property to determine what should
    be saved in state. Other form elements use the value property instead.
  1. How do you watch for a form submit? How can you trigger
    a form submit?
  • Can watch for the submit with an onSubmit handler on the form element.
  • Can trigger the form submit with a button click.

0개의 댓글