Skip to content

Instantly share code, notes, and snippets.

@jmercedes
Created September 7, 2018 20:36
Show Gist options
  • Save jmercedes/f327ca1387397c465e6db01278c920d5 to your computer and use it in GitHub Desktop.
Save jmercedes/f327ca1387397c465e6db01278c920d5 to your computer and use it in GitHub Desktop.
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