Skip to content

Commit a076000

Browse files
committed
Commit everything
1 parent e9732c1 commit a076000

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const BaseURL = 'http://localhost:8000';
88
function App() {
99
return (
1010
<div className="app">
11+
<h1>Backend listeners</h1>
1112
<ServerSentEvents />
1213
<FetchWithPolling />
1314
</div>

src/components/Polling.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Table } from './Table';
44

55
export const FetchWithPolling = () => {
66
const [stockPrices, setStockPrices] = useState([]);
7+
const [numOfConnections, setNumOfConnections] = useState(0);
78

89
const fetchStockPrice = () => {
910
fetch(`${BaseURL}/realtime-price-polling`).then((res) => res.json().then((result) => setStockPrices(result.data)));
@@ -13,16 +14,18 @@ export const FetchWithPolling = () => {
1314
fetchStockPrice();
1415
const pollingInterval = setInterval(() => {
1516
fetchStockPrice();
17+
setNumOfConnections(numOfConnections + 1)
1618
}, 5000); // poll every 5 seconds
1719

1820
return () => {
1921
clearInterval(pollingInterval);
2022
};
21-
}, []);
23+
}, [numOfConnections]);
2224

2325
return (
2426
<div>
25-
<h1>Polling</h1>
27+
<h2>Polling</h2>
28+
<p>Connections: {numOfConnections}</p>
2629
<Table stockPrices={stockPrices} />
2730
</div>
2831
);

src/components/ServerSentEvents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const ServerSentEvents = () => {
3838

3939
return (
4040
<div>
41-
<h1>Server Sent Events</h1>
41+
<h2>Server Sent Events</h2>
4242
<Table stockPrices={stockPrices} />
4343
</div>
4444
);

src/components/WebSocket.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
export const WebSocket = () => {
4+
5+
}

0 commit comments

Comments
 (0)