Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2주차] 고윤정 미션 제출합니다. #2

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
17 changes: 11 additions & 6 deletions src/components/InputBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function InputBox({ todoList, setTodoList }) {
}
`;

const [text, setText] = useState('');
const [text, setText] = useState(''); // input에 입력한 값
const inputRef = useRef(null);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 form을 사용하지 않아서 form을 사용했을 때 새로고침을 방지해야하는군요!! 배워갑니다!!!


// form 제출 시 새로고침 방지
Expand All @@ -53,20 +53,24 @@ export default function InputBox({ todoList, setTodoList }) {
// input 값 가져오기
function onChangeInput(e) {
setText(e.target.value);
//e.target에 있는 <input.../>으로부터 value 값을 가져옴
// e.target에 있는 <input.../>으로부터 value 값을 가져옴
}

// + 버튼 클릭(form 제출)
function onClickButton() {
//todoItemList에 값 추가
// 공백 입력 방지
if (text.trim() === '') return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공백 입력을 방지한 부분 좋습니다👍🏻

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

캬.. 공백 방지까지...디테일의 은혜가 끝이 없군요


// todoItemList에 값 추가
const AddTodoList = todoList.concat({
id: todoList.length,
text,
checked: false,
});
setTodoList(AddTodoList);

setText(''); //input 값 초기화
inputRef.current.focus(); // 버튼 누른 자동 포커싱
setText(''); // input 값 초기화
inputRef.current.focus(); // 버튼 누른 후에도 input box에 자동 포커싱
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useRef를 이용해서 input에 포커스를 주는 부분 새롭게 알아갑니다👀👀

}

return (
Expand All @@ -79,8 +83,9 @@ export default function InputBox({ todoList, setTodoList }) {
ref={inputRef}
className="input-box"
placeholder="할일을 입력하세요"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 placeholder하나만으로도 이 사이트의 정체성을 보여주는 것 같아요. 🦖 친절한 사이트...

onChange={onChangeInput} //input 값이 변하면(이벤트 발생) 메소드 실행
onChange={onChangeInput} // input 값이 변하면(이벤트 발생) 메소드 실행
css={inputStyle}
autoFocus
/>
<button
className="add-button"
Expand Down