Last active
June 18, 2020 04:27
-
-
Save Niraj-Fonseka/3769ad9bd822bc4d175cd3af6613d6e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
import './App.css'; | |
import { SensorRequest } from "./sensorpb/sensor_pb" | |
import { SensorClient} from "./sensorpb/sensor_grpc_web_pb" | |
var client = new SensorClient('http://localhost:8000') | |
function App() { | |
const [temp, setTemp] = useState(-9999); | |
const getTemp = () => { | |
console.log("called") | |
var sensorRequest = new SensorRequest() | |
var stream = client.tempSensor(sensorRequest,{}) | |
stream.on('data', function(response){ | |
setTemp(response.getValue()) | |
}); | |
}; | |
useEffect(()=>{ | |
getTemp() | |
},[]); | |
return ( | |
<div> | |
Temperature : {temp} F | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment