Fórum Erro no projeto react TypeError: Cannot read property map of undefined #599322
20/12/2018
0
Olá estou tentando criar uma lista com dados da fake api jsonplaceholder mas não consigo resolver esse erro.
Gostaria de uma ajuda.
Gostaria de uma ajuda.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import React, { Component } from "react" ; import { teste } from "../base/base" ; class Corpo extends Component { constructor(props) { super (props) this .state = { id : 0, name: 0, username: 0, email: 0, address: { street: 0, city: 0 } }; } componentDidMount() { teste().then(users => this .setState()); } render() { return ( <div> <div className= "row" > <div className= "col" > <div className= "card mt-2" > <div className= "card-header" > Pessoas </div> <table class= "table" > <thead> <tr> <th ></th> <th >Nome</th> <th >Username</th> <th >Email</th> <th >Rua</th> <th >Cidade</th> </tr> </thead> <tbody> { this .state.users.map((item,indice) => { return ( <tr key= > <td>{item.name}</td> <td>{item.username}</td> <td>{item.email}</td> <td>{item.address.street}</td> <td>{item.address.city}</td> </tr> ) }) } </tbody> </table> </div> </div> </div> </div> ) } } export default Corpo; |

Carlos Santos
Curtir tópico
+ 0
Responder
Post mais votado
20/12/2018
Acabei conseguindo arrumar o erro e pegar os dados da api...
[quote}this.state = {
users : []
}
componentDidMount() {
teste().then(dados => this.setState(users:dados));
}
[quote}this.state = {
users : []
}
componentDidMount() {
teste().then(dados => this.setState(users:dados));
}
Carlos Santos

Responder
Gostei + 2