Skip to content

Commit

Permalink
Do not try to render sensor reading with invalid data
Browse files Browse the repository at this point in the history
  • Loading branch information
user890104 committed Dec 25, 2023
1 parent 3ec4251 commit 781a28f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/widgets/SensorReading/SensorReading.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;

0 comments on commit 781a28f

Please sign in to comment.