인프런 커뮤니티 질문&답변
약관 체크하는 부분 질문입니다.
작성
·
196
0
체크 눌러도 가입하기에서 진행이 안되길래 콘솔찍어서 확인해봤는데 저렇게 뜨네요.
제 생각에는 e.target.checked랑 term이랑 같은 값을 반환해야하는 것 같은데,
term은 항상 false를 반환합니다.
어디서 잘못된 걸까요?ㅠㅠㅠ
(코드 더 살펴보고 있는데 password check부분도 똑같이 값이 안들어와요...😭😭
혹시몰라 전체코드 첨부합니다...
import { Button, Form, Input } from 'antd';
import Checkbox from 'antd/lib/checkbox/Checkbox';
import Head from 'next/head';
import React, { useCallback, useState } from 'react';
import styled from 'styled-components';
import useInput from '../hooks/useInput';
const ErrorMessage = styled.div`
color: red;
`;
const signup = () => {
const [id, onChangeId] = useInput('');
const [nickname, onChangeNickname] = useInput('');
const [password, onChangePassword] = useInput('');
const [passwordCheck, setPasswordCheck] = useState('');
const [passwordError, setPasswordError] = useState('');
const onChangePasswordCheck = useCallback(
(e) => {
setPasswordError(e.target.value !== password);
setPasswordCheck(e.target.value);
},
[password]
);
const [term, setTerm] = useState(false);
const [termError, setTermError] = useState(false);
const onChangeTerm = useCallback((e) => {
setTermError(false);
setTerm(e.target.checked);
console.log(e.target.checked);
console.log(term);
}, []);
const onsubmit = useCallback(() => {
if (password !== passwordCheck) {
return setPasswordError(true);
}
if (!term) {
console.log(term);
return setTermError(true);
}
console.log(id, nickname, password);
}, [id, nickname, password]);
return (
<>
<Head>
<title>회원가입 | NodeBird</title>
</Head>
<Form onFinish={onsubmit}>
<div>
<label htmlFor="user-id">아이디</label>
<Input name="user-id" type="id" value={id} required onChange={onChangeId} />
</div>
<div>
<label htmlFor="user-nickname">닉네임</label>
<Input
name="user-nickname"
type="text"
value={nickname}
required
onChange={onChangeNickname}
/>
</div>
<div>
<label htmlFor="user-password">비밀번호</label>
<Input
name="user-password"
type="password"
value={password}
required
onChange={onChangePassword}
/>
</div>
<div>
<label htmlFor="user-passwordCheck">비밀번호 체크</label>
<Input
name="user-passwordCheck"
type="password"
value={passwordCheck}
required
onChange={onChangePasswordCheck}
/>
{passwordError && <ErrorMessage>비밀번호가 일치하지 않습니다.</ErrorMessage>}
</div>
<div>
<Checkbox name="user-term" checked={term} onChange={onChangeTerm}>
회원가입에 동의합니다.
</Checkbox>
{termError && <ErrorMessage>약관에 동의하셔야 합니다.</ErrorMessage>}
</div>
<div style={{ marginTop: 10 }}>
<Button type="primary" htmlType="submit">
가입하기
</Button>
</div>
</Form>
</>
);
};
export default signup;




