-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathapp.js
More file actions
37 lines (32 loc) · 859 Bytes
/
Copy pathapp.js
File metadata and controls
37 lines (32 loc) · 859 Bytes
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
import { h, Component } from 'preact';
import { connect } from 'preact-redux';
import reduce from '../reducers/reducers';
import * as actions from '../actions/todo';
import TodoItem from './todo-item';
@connect(reduce, actions)
export default class App extends Component {
addTodos = () => {
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>
);
}
}