Skip to content

Commit dc9215f

Browse files
committed
Add a state component
1 parent 91e6479 commit dc9215f

4 files changed

Lines changed: 40 additions & 12 deletions

File tree

src/components/AddTodo.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var React = require('react');
2+
3+
var AddTodo = React.createClass({
4+
handleClick: function(e) {
5+
var node = this.refs.input
6+
var text = node.value.trim()
7+
this.props.onAddClick(text)
8+
node.value = ''
9+
},
10+
render: function() {
11+
return (
12+
<div>
13+
<input type='text' ref='input' />
14+
<button onClick={this.handleClick}>
15+
Add
16+
</button>
17+
</div>
18+
);
19+
}
20+
});
21+
22+
23+
module.exports = AddTodo;

src/components/TodoApp.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/containers/TodoApp.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
import TodoList from '../components/TodoList'
3+
import AddTodo from '../components/AddTodo'
4+
5+
export default function TodoApp(props) {
6+
return (
7+
<div className="todoApp">
8+
<AddTodo
9+
onAddClick={function(text) {
10+
console.log(text)
11+
}}
12+
/>
13+
<TodoList data={props.data}/>
14+
</div>
15+
)
16+
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { render } from 'react-dom'
3-
import TodoApp from './components/TodoApp'
3+
import TodoApp from './containers/TodoApp'
44

55
var data = [
66
{id: 1, text: "Do The App", completed: 0},

0 commit comments

Comments
 (0)