728x90 300x250 SMALL 프로그래밍2 React에서 체크박스를 포함한 다중 입력 폼 구현하기 예제 코드import React, { useState } from "react";function MultiInputForm() { // 초기 상태 설정 const [formData, setFormData] = useState({ username: "", email: "", agreeToTerms: false, // 체크박스 상태 }); // 입력 값 변경 핸들러 const handleChange = (e) => { const { name, value, type, checked } = e.target; // e.target에서 필요한 값 추출 setFormData({ ...formData, // 기존 값 복사 [name]: type === "checkb.. 2025. 1. 29. 객체/배열 디스트럭처링 시 기본값 설정하기 디스트럭처링을 할 때, 값이 존재하지 않으면 기본값을 설정할 수 있다.이 경우, 변수에 기본값을 지정하면 해당 값이 없을 때 대신 사용된다. 객체 디폴트 값const person = { name: "Alice" };// age가 없으면 30을 기본값으로 설정const { name, age = 30 } = person;console.log(name); // "Alice"console.log(age); // 30 (기본값) 배열 디폴트 값const numbers = [1];// 두 번째 값이 없으면 2를 기본값으로 설정const [first, second = 2] = numbers;console.log(first); // 1console.log(second); // 2 2025. 1. 26. 이전 1 다음 728x90 반응형 LIST