-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathapp.js
38 lines (34 loc) · 876 Bytes
/
app.js
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
32
33
34
35
36
37
38
import { h, Component } from 'preact';
import { connect } from 'preact-redux';
import reduce from '../reducers';
import * as actions from '../actions';
import TodoItem from './todo-item';
@connect(reduce, actions)
export default class App extends Component {
addTodos = () => {
if (this.state.text) {
this.props.addTodo(this.state.text);
this.setState({ text: '' });
}
};
removeTodo = (todo) => {
this.props.removeTodo(todo);
};
updateText = (e) => {
this.setState({ text: e.target.value });
};
render({ todos }, { text }) {
return (
<div id="app">
<form onSubmit={this.addTodos} action="javascript:">
<input value={text} onInput={this.updateText} placeholder="New ToDo..." />
</form>
<ul>
{ todos.map(todo => (
<TodoItem key={todo.id} todo={todo} onRemove={this.removeTodo} />
)) }
</ul>
</div>
);
}
}