From 781a28f97f1e0df2906b6997104013278848275a Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Mon, 25 Dec 2023 19:57:29 +0200 Subject: [PATCH] Do not try to render sensor reading with invalid data --- src/widgets/SensorReading/SensorReading.jsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/widgets/SensorReading/SensorReading.jsx b/src/widgets/SensorReading/SensorReading.jsx index 973d376..221c9b4 100644 --- a/src/widgets/SensorReading/SensorReading.jsx +++ b/src/widgets/SensorReading/SensorReading.jsx @@ -20,6 +20,11 @@ const SensorReading = ({ formatDefault, formatDistanceToNow, } = useDateTimeFormatter(); + + if (typeof timestamp === 'undefined' || typeof value === 'undefined') { + return null; + } + const lastUpdate = new Date(timestamp); const formattedTimestamp = formatDefault(lastUpdate) + ' (' + formatDistanceToNow(lastUpdate) + ')'; const unit = units[type]; @@ -50,8 +55,8 @@ const SensorReading = ({ SensorReading.propTypes = { type: PropTypes.string.isRequired, label: PropTypes.string.isRequired, - timestamp: PropTypes.number.isRequired, - value: PropTypes.number.isRequired, + timestamp: PropTypes.number, + value: PropTypes.number, }; export default SensorReading;