-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
191725f
dcd69b6
1ffb7cd
a0feae0
bce271d
7adec98
2ebb7b2
773ed2f
7017327
0ef98ee
91f365f
c105875
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ export default function InputBox({ todoList, setTodoList }) { | |
} | ||
`; | ||
|
||
const [text, setText] = useState(''); | ||
const [text, setText] = useState(''); // input에 입력한 값 | ||
const inputRef = useRef(null); | ||
|
||
// form 제출 시 새로고침 방지 | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 공백 입력을 방지한 부분 좋습니다👍🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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에 자동 포커싱 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useRef를 이용해서 input에 포커스를 주는 부분 새롭게 알아갑니다👀👀 |
||
} | ||
|
||
return ( | ||
|
@@ -79,8 +83,9 @@ export default function InputBox({ todoList, setTodoList }) { | |
ref={inputRef} | ||
className="input-box" | ||
placeholder="할일을 입력하세요" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 form을 사용하지 않아서 form을 사용했을 때 새로고침을 방지해야하는군요!! 배워갑니다!!!