Skip to content

Instantly share code, notes, and snippets.

@adash333
Created September 14, 2019 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adash333/bd47521c5a18e7487f85698ed9959f1a to your computer and use it in GitHub Desktop.
Save adash333/bd47521c5a18e7487f85698ed9959f1a to your computer and use it in GitHub Desktop.
import { Component, State, Listen } from '@stencil/core';
@Component({
tag: 'app-home',
styleUrl: 'app-home.css'
})
export class AppHome {
@State() todos: any;
@State() newTodo;
componentWillLoad() {
this.todos = [{ id: 1, value: 2 }];
}
render() {
return (
<div>
<input onChange={e => this.updateNewTodo(e.target)}/>
<ul>
{this.todos.map((todo) => {
return <my-todo
value={todo.value}
id={todo.id}></my-todo>
})}
</ul>
</div>
);
}
updateNewTodo(newTodo) {
this.todos = [...this.todos, { id: Date.now(), value: newTodo.value }];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment