quando faço o login está retornando esse erro.
TypeError: this.state.fotos.map is not a function Timeline.render C:/Users/dozv/Desktop/Alura/Engenheiro Front-End/React/instalura/src/componentes/Timeline.js:21 18 | 19 | render(){ 20 | return (
21 |
| ^ 22 | { 23 | this.state.fotos.map(foto => ) 24 | }Timeline.js`
import React, { Component } from 'react'; import FotoItem from './Foto';
export default class Timeline extends Component {
constructor(){
super();
this.state = {fotos:[]};
}
componentDidMount(){
fetch(`https://instalura-api.herokuapp.com/api/public/fotos?X-AUTH-TOKEN=${localStorage.getItem('auth-token')}`)///rafael
.then(response => response.json())
.then(fotos => {
this.setState({fotos:fotos});
});
}
render(){
return (
<div className="fotos container">
{
this.state.fotos.map(foto => <FotoItem key={foto.id} foto={foto}/>)
}
</div>
);
}
}
Login.js
import React, { Component } from 'react'; import {browserHistory} from 'react-router';
export default class Login extends Component {
constructor(props){
super(props);
this.state = {msg:this.props.location.query.msg};
}
envia(event){
event.preventDefault();
const requestInfo = {
method:'POST',
body:JSON.stringify({login:this.login.value,senha:this.senha.value}),
headers:new Headers({
'Content-type' : 'application/json'
})
};
fetch('https://instalura-api.herokuapp.com/api/login',requestInfo)
.then(response => {
if(response.ok) {
return response.text();
} else {
throw new Error('não foi possível fazer o login');
}
})
.then(token => {
localStorage.setItem('auth-token',token);
browserHistory.push('/timeline');
})
.catch(error => {
this.setState({msg:error.message});
});
}
render(){
return (
<div className="login-box">
<h1 className="header-logo">Instalura</h1>
<span>{this.state.msg}</span>
<form onSubmit={this.envia.bind(this)}>
<input type="text" ref={(input) => this.login = input}/>
<input type="password" ref={(input) => this.senha = input}/>
<input type="submit" value="login"/>
</form>
</div>
);
}
}
`
alguém teve algum problema parecido?
OBS estou usando as APIs no herokuapp