From b8322417a0031732ff19531c5282fdca072ed196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wahlberg?= Date: Fri, 27 Nov 2020 13:36:48 +0100 Subject: [PATCH] Fix some React errors and warnings --- src/components/Header.js | 2 +- src/components/MenuButton.js | 4 ++-- src/components/TrafficEntry.js | 24 +++++++++++------------- src/components/TrafficList.js | 8 +++++--- src/components/TripSelector.js | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/components/Header.js b/src/components/Header.js index d27a838..1a1197a 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -6,7 +6,7 @@ class Header extends Component { render() { return (
- +

{this.props.title}

); diff --git a/src/components/MenuButton.js b/src/components/MenuButton.js index 6bda14c..0c78162 100644 --- a/src/components/MenuButton.js +++ b/src/components/MenuButton.js @@ -6,13 +6,13 @@ class MenuButton extends Component { return ( ); } else { return ( ); diff --git a/src/components/TrafficEntry.js b/src/components/TrafficEntry.js index 63829ea..0e97297 100644 --- a/src/components/TrafficEntry.js +++ b/src/components/TrafficEntry.js @@ -8,28 +8,26 @@ import warningIcon from '../img/warning.svg'; class TrafficEntry extends Component { render() { let trafficInfo = this.props.departure.info; - let lineInterference = trafficInfo != "" && trafficInfo != null; - let infoElem = <>; - - if (trafficInfo != "" && trafficInfo != null) - infoElem =

{trafficInfo} Visa mer

+ let lineInterference = trafficInfo !== "" && trafficInfo !== null; return ( -
+
-
+
{this.props.departure.time} {lineInterference && - + }
-
+
- {this.props.departure.lineName} - - {this.props.departure.destination} + {this.props.departure.lineName} + + {this.props.departure.destination}
- {infoElem} + {lineInterference && +

{trafficInfo} Visa mer

+ }
diff --git a/src/components/TrafficList.js b/src/components/TrafficList.js index d96e079..c91101c 100644 --- a/src/components/TrafficList.js +++ b/src/components/TrafficList.js @@ -8,18 +8,20 @@ class TrafficList extends Component { render() { let entries = []; + let i = 0; // React requires elems in array to have associated unique key + this.props.departures.forEach(departure => { entries.push( - + ); }); // Add separator between every element const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1); - entries = intersperse(entries, (
)); + entries = intersperse(entries, (
)); // Add separator after the last element - entries.push(
); + entries.push(
); return (
diff --git a/src/components/TripSelector.js b/src/components/TripSelector.js index 838f1b5..d1394c8 100644 --- a/src/components/TripSelector.js +++ b/src/components/TripSelector.js @@ -7,7 +7,7 @@ class TripSelector extends Component {
- + );