From e792bb3483befe133485a1b82c5c4ac22cf23a59 Mon Sep 17 00:00:00 2001 From: wildscotsmen Date: Mon, 8 Oct 2018 00:47:24 -0400 Subject: [PATCH] Made sure that we don't try to fetch IDs that aren't in the database. --- src/components/ViewSightings.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ViewSightings.js b/src/components/ViewSightings.js index 5e0482c..822cf8e 100644 --- a/src/components/ViewSightings.js +++ b/src/components/ViewSightings.js @@ -121,7 +121,7 @@ const styles = theme => ({ class ViewSightings extends React.Component { constructor(props){ - super(props); + super(props); this.handleSubmit = this.handleSubmit.bind(this); } @@ -154,7 +154,13 @@ class ViewSightings extends React.Component { e.preventDefault(); const itemSighting = firebase.database().ref("sightings/" + this.state.id); itemSighting.once("value").then((snapshot) => { + // Die if there's no data for that ID. + if (!snapshot.exists()) { + return; + } + let data = snapshot.val(); + this.setState({ date: data.date, time: data.time,