<commit_before>import { createElement, Component } from 'preact';

let counter = 0;

export default class TodoList extends Component {
	state = { todos: [], text: '' };

	setText = e => {
		this.setState({ text: e.target.value });
	};

	addTodo = () => {
		let { todos, text } = this.state;
		todos = todos.concat({ text, id: ++counter });
		this.setState({ todos, text: '' });
	};

	removeTodo = e => {
		let id = e.target.getAttribute('data-id');
		this.setState({ todos: this.state.todos.filter( t => t.id!=id ) });
	};

	render({ }, { todos, text }) {
		return (
			<form onSubmit={this.addTodo} action="javascript:">
				<input value={text} onInput={this.setText} />
				<button type="submit">Add</button>
				<ul>
					<TodoItems todos={todos} removeTodo={this.removeTodo}/>
				</ul>
			</form>
		);
	}
}


class TodoItems extends Component {
	render({ todos, removeTodo }) {
		return todos.map( todo => (
			<li key={todo.id}>
				<button onClick={removeTodo} data-id={todo.id}>&times;</button>
				{' '}
				{todo.text}
			</li>
		));
	}
}
<commit_msg>Fix remove button adding todos in demo app (#1488)<commit_after>import { createElement, Component } from 'preact';

let counter = 0;

export default class TodoList extends Component {
	state = { todos: [], text: '' };

	setText = e => {
		this.setState({ text: e.target.value });
	};

	addTodo = () => {
		let { todos, text } = this.state;
		todos = todos.concat({ text, id: ++counter });
		this.setState({ todos, text: '' });
	};

	removeTodo = e => {
		let id = e.target.getAttribute('data-id');
		this.setState({ todos: this.state.todos.filter( t => t.id!=id ) });
	};

	render({ }, { todos, text }) {
		return (
			<form onSubmit={this.addTodo} action="javascript:">
				<input value={text} onInput={this.setText} />
				<button type="submit">Add</button>
				<ul>
					<TodoItems todos={todos} removeTodo={this.removeTodo} />
				</ul>
			</form>
		);
	}
}


class TodoItems extends Component {
	render({ todos, removeTodo }) {
		return todos.map( todo => (
			<li key={todo.id}>
				<button type="button" onClick={removeTodo} data-id={todo.id}>&times;</button>
				{' '}
				{todo.text}
			</li>
		));
	}
}

{'fraction_non_alphanumeric': 0.19871205151793928, 'fraction_numerical': 0.0027598896044158236, 'mean_word_length': 3.324055666003976, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '595335', 'n_tokens_mistral': 879, 'n_tokens_neox': 784, 'n_words': 169}