Skip to content

Commit 730ce98

Browse files
committed
feat(coding): とりあえず写経
1 parent ef5cae4 commit 730ce98

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

src/App.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
1-
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
1+
import React, {Component} from 'react';
42

5-
function App() {
6-
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.js</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
22-
</div>
23-
);
24-
}
3+
class App extends Component{
4+
constructor(props){
5+
super(props);
6+
7+
this.state = {
8+
todos: [
9+
{id: "1", text: "todo1"},
10+
{id: "2", text: "todo2"},
11+
{id: "3", text: "todo3"}
12+
]
13+
};
14+
}
15+
16+
deleteTodo(id){
17+
let todos = this.state.todos;
18+
todos = todos.filter((todo) => todo.id !== id);
19+
20+
this.setState({todos: todos});
21+
};
22+
23+
render(){
24+
return(
25+
<ul>
26+
{
27+
this.state.todos.map(
28+
(todo) => {
29+
return (
30+
<li key={todo.id}>{todo.text}
31+
<button onClick={this.state.deleteTodo.bind(this, todo.id)}>×</button>
32+
</li>
33+
);
34+
}
35+
)
36+
}
37+
</ul>
38+
);
39+
}
40+
}
2541

2642
export default App;

0 commit comments

Comments
 (0)