Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import { useState } from 'react';
export default function FormCheck() {
// State 초기화
const [form, setForm] = useState({
agreement: true
});
// 체크박스 변경 시 입력값 State에 반영
const handleFormCheck = e => {
setForm({
...form,
[e.target.name]: e.target.checked
});
};
// [보내기] 버튼 클릭 시 입력값 로그 출력
const show = () => {
console.log(`동의 확인: ${form.agreement ? '동의': '동의하지 않음'}`);
};
return (
<form>
<label htmlFor="agreement">동의합니다:</label>
<input id="agreement" name="agreement" type="checkbox"
checked={form.agreement}
onChange={handleFormCheck} /><br />
<button type="button" onClick={show}>보내기</button>
</form>
);
}
|