Created
September 7, 2018 20:36
-
-
Save jmercedes/f327ca1387397c465e6db01278c920d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import PatientListItem from './PatientListItem' | |
import PatientProfile from './PatientProfile' | |
import { Link, Route, Switch } from 'react-router-dom' | |
export default class PatientList extends Component { | |
state = { | |
pacientes: [] | |
} | |
componentDidMount(){ | |
fetch('https://jsonplaceholder.typicode.com/users') | |
.then( (res) => res.json() ) | |
.then( (data) => { | |
this.setState({ pacientes: data | |
}) | |
}) | |
} | |
render(){ | |
const { pacientes } = this.state | |
console.log(this.state.pacientes) | |
return( | |
<div> | |
{ | |
pacientes.map((paciente) => ( | |
<Link to={`/pacientes/${paciente.id}`} key={paciente.id}> | |
<PatientListItem title={paciente.name} /> | |
</Link> | |
)) | |
} | |
<Route path='/pacientes/:id' component={PatientProfile}/> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment