Created
April 17, 2019 11:29
-
-
Save alpap/3e469d4832168a3304be3fe3dc57b838 to your computer and use it in GitHub Desktop.
preact test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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