Onde foi que eu errei? Ao incluir os dados dinâmicos de likers e comentários, recebi o erro "TypeError: Cannot read property 'map' of undefined" conforme dados abaixo:
class FotoInfo extends Component {
render(){
return (
<div className="foto-in fo">
<div className="foto-info-likes">
{
this.props.foto.likers.map(liker => {
return (<a href="#">{liker.login},</a>)
})
}
curtiram
</div>
<p className="foto-info-legenda">
<a className="foto-info-autor">autor </a>
{this.props.foto.comentario}
</p>
<ul className="foto-info-comentarios">
{
this.props.foto.comentarios.map(comentario => {
return (
<li className="comentario">
<a className="foto-info-autor">{comentario.login} </a>
{comentario.texto}
</li>
);
})
}
</ul>
</div>
);
}
}
TypeError: Cannot read property 'map' of undefined
FotoInfo.render
C:/Users/Pantufa/cursos/react2/instalura/src/componentes/FotoItem.js:22
19 | render(){
20 | return (
21 | <div className="foto-in fo">
> 22 | <div className="foto-info-likes">
| ^ 23 | {
24 | this.props.foto.likers.map(liker => {
25 | return (<a href="#">{liker.login},</a>)
View compiled
(anonymous function)
C:/Users/Pantufa/cursos/react2/instalura/src/componentes/Timeline.js:15
12 | fetch("https://instalura-api.herokuapp.com//api/public/fotos/vitor")
13 | .then(response => response.json())
14 | .then(fotos =>{
> 15 | this.setState({fotos:fotos});
| ^ 16 | });
17 | }
18 |
View compiled
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.
no console:
index.js:1375 The above error occurred in the <FotoInfo> component:
in FotoInfo (at FotoItem.js:79)
in div (at FotoItem.js:76)
in FotoItem (at Timeline.js:23)
in div (at Timeline.js:21)
in Timeline (at App.js:11)
in div (at App.js:9)
in div (at App.js:8)
in App (at src/index.js:8)
Consider adding an error boundary to your tree to customize error handling behavior. Visit https://fb.me/react-error-boundaries to learn more about error boundaries. console.<computed> @ index.js:1375
FotoItem.js:22 Uncaught (in promise) TypeError: Cannot read property 'map' of undefined
at FotoInfo.render (FotoItem.js:22)
at finishClassComponent (react-dom.development.js:15319)
at updateClassComponent (react-dom.development.js:15274)
at beginWork (react-dom.development.js:16262)
at performUnitOfWork (react-dom.development.js:20279)
at workLoop (react-dom.development.js:20320)
at renderRoot (react-dom.development.js:20400)
at performWorkOnRoot (react-dom.development.js:21357)
at performWork (react-dom.development.js:21267)
at performSyncWork (react-dom.development.js:21241)
at requestWork (react-dom.development.js:21096)
at schedule