Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgreenb committed Sep 23, 2019
1 parent 1f7f443 commit 637c531
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ export default class App extends React.Component {
}
}

addItem(value) {
const previousList = this.state.todos;

this.setState({todos: previousList.concat(value)});
}

render() {
const {todos} = this.state;

return (
<div className="App">
<h1>TodoList</h1>
<TodoList todos={todos} />
<TodoList todos={todos} onAddItem={value => this.addItem(value)}/>
</div>
);
}
Expand Down
40 changes: 27 additions & 13 deletions src/TodoList/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import React from "react";

export default class TodoList extends React.Component {
render() {
const { todos } = this.props;
constructor(props) {
super(props);

return (
<div>
<ul>
{todos.map(todoItem => (
<li>{todoItem}</li>
))}
</ul>
</div>
);
}
}
this.state = {};
}
setTodoValue(event) {
const value = event.target.value;

this.setState({value});
}

render() {
const { todos, onAddItem} = this.props;
const { value } = this.state;

return (
<div>
<ul>
{todos.map(todoItem => (
<li>{todoItem}</li>
))}
</ul>
<input onChange={event => this.setTodoValue(event)}/>
<button onClick={() => onAddItem(value)}>Add</button>
</div>
)
}
}

0 comments on commit 637c531

Please sign in to comment.