Skip to content

Instantly share code, notes, and snippets.

@Niraj-Fonseka
Last active June 18, 2020 04:27
Show Gist options
  • Save Niraj-Fonseka/3769ad9bd822bc4d175cd3af6613d6e1 to your computer and use it in GitHub Desktop.
Save Niraj-Fonseka/3769ad9bd822bc4d175cd3af6613d6e1 to your computer and use it in GitHub Desktop.
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