import React from 'react'; import ModalBox from './ModalBox.js'; import './App.css'; const Empty = Empty />; const Error = Error />; class MovementsPage extends React.Component { constructor(props) { super(props); this.state = {loggedIn: props.loggedIn, movements: []}; } componentDidMount() { fetch(this.props.targetUrl + '/movements', {credentials: 'include'}) .then(response => response.json()) .then(data => this.setState({movements: data.movements, loggedIn: data.logged_in})) .catch(error => {console.log(error); this.setState({error: true})}); } componentWillUnmount() { this.setState({error: false, movements: []}); } handleTable() { if (this.state.movements !== undefined) { return ; } else { return Empty; } } render() { const movements = ; if (this.state.error) { return Error; } if (this.state.loggedIn) { return movements; } else { return (You have to login first! />); } } } export default MovementsPage;