class TodoList extends Preact.Component {
constructor(props) {
super(props);
this.state = { todos: [], text: "" };
this.setText = this.setText.bind(this);
this.addTodo = this.addTodo.bind(this);
}
setText(e) {
this.setState({ text: e.target.value });
}
addTodo(e) {
e.preventDefault();
let { todos, text } = this.state;
todos = todos.concat({ text });
this.setState({ todos, text: "" });
}
render() {
const { todos, text } = this.state;
return htm`<form onSubmit=${this.addTodo}>
<label>
<span>Add Todo</span>
<input value=${text} onInput=${this.setText} />
</label>
<button type="submit">Add</button>
<ul>
${todos.map((todo) => htm`<li>${todo.text}</li>`)}
</ul>
</form>`;
}
}