forked from confluentinc/demo-scene
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
34 lines (28 loc) · 806 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import logo from './logo.svg';
import './App.css';
import {useState, useEffect} from 'react';
const WS_URL = "ws://localhost:8080/ws";
const ws = new WebSocket(WS_URL);
function App() {
const [webSocket, _] = useState(ws);
const [total, setTotal] = useState(null);
useEffect(() => {
webSocket.onmessage = (event) => {
const payload = JSON.parse(event.data);
const total = payload['TOTAL'];
const formatted = total.toLocaleString(undefined, {minimumFractionDigits: 2});
setTotal(formatted);
};
}, [webSocket]);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
{total || "...waiting..."}
</p>
</header>
</div>
);
}
export default App;