반응형
import { useState } from 'react';
function App() {
const [toDo, setToDo] = useState('');
const [toDos, setToDos] = useState([]);
const onChange = (event) => {
setToDo(event.target.value);
};
const onSubmit = (event) => {
event.preventDefault();
if (toDo === '') {
return;
}
setToDos((currentArray) => [toDo, ...currentArray]);
setToDo('');
console.log(toDos);
};
return (
<div>
<h1>Todo Count : {toDos.length}</h1>
<form onSubmit={onSubmit}>
<input
type="text"
placeholder="Input Value!!"
onChange={onChange}
value={toDo}
/>
<button>Add</button>
</form>
<hr />
<ul>
{toDos.map((todoItem, index) => (
<li key={index}>{todoItem}</li>
))}
</ul>
</div>
);
}
export default App;
반응형
'[====== Development ======] > React' 카테고리의 다른 글
이미지 파일 선택하여 Preview 출력 (0) | 2022.03.16 |
---|---|
[React Study] Link Page (0) | 2022.01.16 |
Rounded Input textbox (0) | 2022.01.11 |
[React Study] Movie List (0) | 2022.01.11 |
[React Study] CoinTracker (0) | 2022.01.08 |