diff --git a/index.html b/index.html index 2b58884..0b5da0a 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ HelloJS React Basic Demo + @@ -12,4 +13,4 @@ - \ No newline at end of file + diff --git a/src/App.jsx b/src/App.jsx index c869b09..b2d3742 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,14 +3,27 @@ import TodoList from './TodoList.jsx' import TodoAddForm from './TodoAddForm.jsx' class TodoApp extends React.Component { + state = { + todos: ['Hello','world'] + } + addTodo = (val) => { + this.state.todos.push(val); + this.setState({todos:this.state.todos}); + } + removeTode = (id) => { + this.state.todos.splice(id,1) + this.setState({todes:this.state.todes}) + } + render() { return (

Todo App

- 123 + +
); } } -export default TodoApp; \ No newline at end of file +export default TodoApp; diff --git a/src/TodoAddForm.jsx b/src/TodoAddForm.jsx index fbf6003..c2ec99a 100644 --- a/src/TodoAddForm.jsx +++ b/src/TodoAddForm.jsx @@ -1,18 +1,32 @@ import React from 'react' class TodoAddForm extends React.Component { - state = { - inputText: '' + constructor(props){ + super(props) + this.state = { + inputText: '' + } } - + handleChange = (e) => { + + this.setState({inputText: e.target.value}) + } + + addTodo = () => { + if (this.state.inputText !== "") { + this.props.addTodo(this.state.inputText.trim()); + this.setState({inputText:""}) + } + } + render() { return (
- - + +
); } } -export default TodoAddForm; \ No newline at end of file +export default TodoAddForm; diff --git a/src/TodoItem.jsx b/src/TodoItem.jsx index 170af86..34e5662 100644 --- a/src/TodoItem.jsx +++ b/src/TodoItem.jsx @@ -1,13 +1,25 @@ import React from 'react' class TodoItem extends React.Component { + constructor(props){ + super(props) + } + + removeTode = () => { + this.props.removeTode(this.props.pid) + } + render() { return (
- +
); } } -export default TodoItem; \ No newline at end of file +export default TodoItem; diff --git a/src/TodoList.jsx b/src/TodoList.jsx index d588dc4..ec1f63c 100644 --- a/src/TodoList.jsx +++ b/src/TodoList.jsx @@ -2,13 +2,22 @@ import React from 'react' import TodoItem from './TodoItem.jsx' class TodoList extends React.Component { + constructor(props){ + super(props) + } render() { return (
- + { + this.props.todos.map((todo, i) => { + return( + + ); + }) + }
); } } -export default TodoList; \ No newline at end of file +export default TodoList;