Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Cannot read property 'login' of undefined

Olá, pessoal! Estou com o seguinte erro na aula 4 no vídeo 3: https://prnt.sc/he0v6i

Como também pode ver nesse tópico: https://cursos.alura.com.br/forum/topico-cannot-read-property-params-of-undefined-48516

O rapaz deu um console.log(this.props); e retornou apenas: { }

Também fiz a mesma coisa como mostra no print no primeiro link

App.js


class App extends Component {

    render() {
        console.log(this.props);
        return (
                <div id="root">
                    <div className="main">
                        <Header />
                        <Timeline login={this.props.params.login}/>
                    </div>
                </div>
        );
    }
}

Timeline.js


export default class Timeline extends Component {

    constructor() {
        super();
        this.state = {fotos: []};
    }

    componentDidMount() {

        let urlPerfil;

        if(this.props.login === undefined) {
            urlPerfil = `http://localhost:8080/api/fotos?X-AUTH-TOKEN=${localStorage.getItem('auth-token')}`;
        } else {
            urlPerfil = `http://localhost:8080/api/public/fotos/${this.props.login}`;
        }

        fetch(urlPerfil)
        .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>            
        );
    }
}
3 respostas

Alguém poderia ajudar?

Lucas, o seu login, está vindo como props na hora que você chama o <App />?

solução!

Pra eu poder terminar as aulas, tive que colocar o React Router 3