Update code to use refs

This commit is contained in:
Shreya 2020-03-10 00:39:35 +05:30
parent e81c044a17
commit 67d88e8ab2
1 changed files with 4 additions and 3 deletions

View File

@ -20,6 +20,7 @@ class MapPageComponent extends AuthComponent {
telemetry: [], telemetry: [],
telemetryLastTimestamp: null telemetryLastTimestamp: null
}; };
this.telemConsole = React.createRef();
} }
events = { events = {
@ -66,8 +67,8 @@ class MapPageComponent extends AuthComponent {
telemetry: newTelem, telemetry: newTelem,
telemetryLastTimestamp: res['timestamp'] telemetryLastTimestamp: res['timestamp']
}); });
var telemConsole = document.querySelector('div.telemetry-console'); var telemConsoleRef = this.telemConsole.current;
telemConsole.scrollTop = telemConsole.scrollHeight - telemConsole.clientHeight telemConsoleRef.scrollTop = telemConsoleRef.scrollHeight - telemConsoleRef.clientHeight
this.props.onStatusChange(); this.props.onStatusChange();
} }
}); });
@ -142,7 +143,7 @@ class MapPageComponent extends AuthComponent {
renderTelemetryConsole() { renderTelemetryConsole() {
return ( return (
<div className="telemetry-console"> <div className="telemetry-console" ref={this.telemConsole}>
{ {
this.state.telemetry.map(this.renderTelemetryEntry) this.state.telemetry.map(this.renderTelemetryEntry)
} }