Skip to content

Instantly share code, notes, and snippets.

@alpap
Created April 17, 2019 11:29
Show Gist options
  • Save alpap/3e469d4832168a3304be3fe3dc57b838 to your computer and use it in GitHub Desktop.
Save alpap/3e469d4832168a3304be3fe3dc57b838 to your computer and use it in GitHub Desktop.
preact test
export default class TodoList extends Component {
state = { todos: [], text: '', count: 0 };
setText = e => {
this.setState({ text: e.target.value });
};
addTodo = () => {
let { todos, text, count } = this.state;
todos = todos.concat({ text: text, id: count++ });
this.setState({ todos, text: '', count: count++ });
};
removeTodo = id => {
let { todos, text, count } = this.state;
todos = todos.filter(todo => {
todo.id != id;
});
this.setState({ todos, text: '', count: count });
};
render({}, { todos, text }) {
return (
<div>
<input style="margin-left:30px" value={text} onInput={this.setText} />
<button onClick={this.addTodo}>Add</button>
<ul>
{todos.map(todo => (
<li>
<p style="font-size:20px">{todo.text + ' with id ' + todo.id}</p>
</li>
))}
</ul>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment