Guest User

Untitled

a guest
Nov 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class TodoItem extends React.Component{
  2. constructor(props){
  3. super(props)
  4. }
  5. removeItem = () => {
  6. /* code to remove the item*/
  7. this.props.update()
  8. }
  9. render(){
  10. return(
  11. <div>{props.title} - <span onClick={this.removeItem}>delete</span></div>
  12. )
  13. }
  14. }
  15. class TodoItems extends React.Component{
  16. constructor(props){
  17. super(props)
  18. this.state = {items: []}
  19. this.update = this.update.bind(this)
  20. this.update()
  21. }
  22. update(){
  23. axios.get("/api").then(r=> this.setState({items: r.data})})
  24. }
  25. render(){
  26. return(
  27. <div>{this.state.items.map(item => <TodoItem {...item} key={item.id} update={this.update}/> )} </div>
  28. )
  29. }
  30. }
Add Comment
Please, Sign In to add comment