11import React , { Component } from 'react' ;
22import Form from './Form' ;
3+ import axios from 'axios' ;
34
45export class Task extends Component {
56 constructor ( props ) {
@@ -14,8 +15,8 @@ export class Task extends Component {
1415 }
1516
1617 componentDidMount ( ) {
17- fetch ( '/api/v1.0.0/tasks' )
18- . then ( ( res ) => res . json ( ) )
18+ axios . get ( '/api/v1.0.0/tasks' )
19+ . then ( ( res ) => res . data )
1920 . then ( ( { tasks } ) => this . setState ( { tasks : tasks . reduce ( ( obj , item ) => ( { ...obj , [ item . _id ] : item } ) , { } ) } ) )
2021 . catch ( ( err ) => this . setState ( { message : err . toString ( ) } ) )
2122 }
@@ -31,7 +32,7 @@ export class Task extends Component {
3132
3233 onDelete ( e , id ) {
3334 e . preventDefault ( )
34- if ( window . confirm ( "Are you sure?" ) ) {
35+ if ( window . confirm ( "Are you sure?" ) ) { // eslint-disable-line
3536 const { tasks = { } } = this . state ;
3637 delete tasks [ id ] ;
3738 this . setState ( { tasks : { ...tasks } } )
@@ -60,7 +61,7 @@ export class Task extends Component {
6061 < div className = "task-component" >
6162 < Form ref = { ( ref ) => this . form = ref } onSuccess = { this . onSuccess } />
6263 < ul >
63- { Object . values ( tasks ) . map ( this . renderTask ) }
64+ { Object . keys ( tasks ) . map ( ( key , index ) => this . renderTask ( tasks [ key ] , index ) ) }
6465 </ ul >
6566 </ div >
6667 ) ;
0 commit comments