Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- FGVC
- 3d
- REACT
- 알고리즘
- Meta Learning
- algorithm
- clean code
- SSL
- 자료구조
- GAN
- Python
- pytorch
- nerf
- classification
- Vision
- Depth estimation
- cs
- CV
- ML
- computervision
- math
- Front
- nlp
- dl
- 머신러닝
- web
- 딥러닝
- PRML
- Torch
- FineGrained
- Today
- Total
KalelPark's LAB
[ React ] TodoList 만들기 본문
import React, {Component} from "react";
export default class App extends Component {
state = {
todoData : [
{
id : "1",
title : "공부하기",
completed : true
},
{
id : "2",
title : "책 읽기",
completed : false
},
{
id : "1",
title : "과제하기",
completed : false
}
],
value : ""
};
btnStyle = {
color : "#fff",
border : "none",
padding : "5px 9px",
borderRadius : "50%",
cursor : "pointer",
float : "right"
}
getStyle = () => {
return {
padding : "10px",
borderBottom : "1px #ccc dotted",
textDecoration : "none",
};
};
handleClick = (id) => {
let newTodoData = this.state.todoData.filter((data) => data.id !== id);
this.setState({todoData : newTodoData})
}
handleChange = (e) => {
this.setState({value : e.target.value});
};
handleSubmit = (e) => {
e.preventDefault();
let newTodo = {
id : Date.now(),
title : this.state.value,
complete : false
};
this.setState({todoData : [...this.state.todoData, newTodo]});
}
render() {
return (
<div className = "container">
<div className = "todoBook">
<div className = "title">
<h1>할일 목록</h1>
</div>
{this.state.todoData.map((data) => (
<div style = {this.getStyle()} key = {data.id}>
<p>
<input type="checkbox" defaultChecked={data.completed}/>
{data.title}
<button style={this.btnStyle} onClick = {() => this.handleClick(data.id)}>x</button>
</p>
</div>
))}
<form style = {{display : "flex"}} onSubmit = {this.handleSubmit}>
<input
type = "text"
name = "value"
style = {{flex : "10", padding : "5px"}}
placeholder = "해야 할일을 입력하세요."
value = {this.state.value}
onChange = {this.handleChange}
/>
<input
type = "submit"
value = "입력"
className = "btn"
style = {{flex : "1"}}
/>
</form>
</div>
</div>
)
}
}
'Study > React' 카테고리의 다른 글
[React] React 작업환경 구축 및 관련 설명 (0) | 2023.03.15 |
---|---|
[React] React Hooks란? (0) | 2023.03.14 |
[ React ] this란? (0) | 2023.02.01 |
[ React ] JSX Key, React State란? (0) | 2023.01.31 |
[ React ] WebPack, Babel이란? (0) | 2023.01.30 |
Comments